#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

// less_equal if supports multiple items
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    dataSet;
const long long MOD = 100000000007;
const long long M = 500100;
long long a[M], k,n;
pair<long long,long long> b[M];
pair<long long,long long> d[M];
void tryuse(pair<long long,long long> &x, long long y, long long index) {
    if (x.second > y) {
        x = {index, y};
    }
}
void out(pair<long long,long long> x) {
    printf("{%lld %lld}\n ",x.first, x.second);
}

int main ( )
{
    scanf("%lld %lld",&k,&n);
    long long t = min(10 * k, n -1);
    for (long long i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a, a+n);
    for (long long i = 0; i < n - 1; i++) {
        b[i] = {a[i+1] - a[i], i};
    }
    sort(b, b+n-1);

    for (long long i = 0; i < t; i++) {
        d[i] = {b[i].second, b[i].first};
    }
    sort(d, d + t);
    pair<long long,long long> f[3][5050][3];
    long long current = 1;
    long long last = 0;
    for (long long i = 0; i <= k; i++) {
        for (long long sta = 0; sta <= 1; sta++) {
            f[current][i][sta] = {-10,1000000000};
        }
    }
    f[current][0][0] = {-10, 0};
    f[current][1][1] = {d[0].first, d[0].second};\
    for (long long i = 1; i <t; i++) {
        swap(current, last);
        for (long long j = 0; j <= k; j++) {
            f[current][j][0] = {-10, 1000000000};
            if (i >= j) {
                tryuse(f[current][j][0], f[last][j][0].second, f[last][j][0].first);
                tryuse(f[current][j][0], f[last][j][1].second, f[last][j][1].first);
            }
            //printf("%lld,%lld 0: %lld %lld\n",i, j, f[current][j][0].first, f[current][j][0].second);

            f[current][j][1] = {-10, 1000000000};
            if (j > 0 && i+1 >= j) {
                if (f[last][j-1][1].first < d[i].first - 1) {
                    tryuse(f[current][j][1], f[last][j-1][1].second + d[i].second, d[i].first);
                }
                tryuse(f[current][j][1],f[last][j-1][0].second + d[i].second, d[i].first);
            }
            //printf("%lld,%lld 1: %lld %lld\n",i,j,f[current][j][1].first, f[current][j][1].second);
        }
    }
    pair<long long,long long> ans  = {-10, 1000000000};
    tryuse(ans, f[current][k][0].second, 0);
    tryuse(ans, f[current][k][1].second, 0);
    cout<< ans.second;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N=500010;

int n,k,a[N],g[N];
double f[N];

inline void dp(double x){
  for(int i=2;i<=n;i++){
    if(f[i-1]>f[i-2]+a[i]-a[i-1]+x)
      f[i]=f[i-2]+a[i]-a[i-1]+x,g[i]=g[i-2]+1;
    else
      f[i]=f[i-1],g[i]=g[i-1];
  }
}

int main(){
#ifdef ljn
  freopen("1.in","r",stdin);
  freopen("1.out","w",stdout);
#endif
  scanf("%d%d",&k,&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  sort(a+1,a+1+n);
  double l=-1e9,r=1e9,mid;
  while(r-l>1e-6){
    mid=(l+r)/2;
    dp(mid);
    if(g[n]>=k) l=mid;
    else r=mid;
  }
  dp(mid=(l+r)/2);
  printf("%lld\n",(long long)(f[n]-k*mid+1e-3));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 7;
const int K = 5e3 + 3;
const int INF = 4e9;

int k, n;
int t[N], a[N];
vector<pair<int,int> > z;
vector<int> id;
int dp[2][K][2];

void minimize(int &x,int y) {
	if (y < x) x = y;
}

int main() {
	ios_base::sync_with_stdio(false);	cin.tie(0);
	cin >> k >> n;
	for (int i = 1;i <= n;++i) cin >> t[i];
	sort(t + 1,t + n + 1);
	for (int i = 1; i <= n - 1; ++i) z.push_back(make_pair(t[i + 1] - t[i], i));
	sort(z.begin(), z.end());

	for (int i = 0; i < min((int)z.size(), k << 2); ++i) {
		id.push_back(z[i].second);
		id.push_back(z[i].second + 1);
	}

	sort(id.begin(), id.end());
	id.erase(unique(id.begin(), id.end()), id.end());

	sort(id.begin(), id.end());
	id.resize(unique(id.begin(), id.end()) - id.begin());

	n = 0;
	for (int i = 0;i < id.size();++i) a[++n] = t[id[i]];

	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j <= min(n >> 1, k); ++j) {
			for (int last = 0; last < 2; ++last) {
				dp[i][j][last] = INF;
			}
		}
	}

	dp[0][0][0] = 0;
	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j <= min(i >> 1, k); ++j) {
			for (int last = 0; last < 2; ++last) {
				if (dp[0][j][last] == INF) {
					continue;
				}

				for (int chosen = 0; chosen < 2; ++chosen) {
					if (last && chosen) continue;
					minimize(dp[1][j + chosen][chosen], dp[0][j][last] + (chosen ? (a[i] - a[i - 1]) : 0));
				}
			}
		}

		for (int j = 0; j <= min(i >> 1, k); ++j) for (int last = 0; last < 2; ++last) {
			dp[0][j][last] = dp[1][j][last];
			dp[1][j][last] = INF;
		}
	}

	cout << min(dp[0][k][0], dp[0][k][1]) << endl;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 7;
const int K = 5e3 + 3;
const int INF = 4e9;

int k, n;
int t[N], a[N];
vector<pair<int,int> > z;
vector<int> id;
int dp[2][K][2];

void minimize(int &x,int y) {
	if (y < x) x = y;
}

int main() {
	ios_base::sync_with_stdio(false);	cin.tie(0);
	cin >> k >> n;
	for (int i = 1;i <= n;++i) cin >> t[i];
	sort(t + 1,t + n + 1);
	for (int i = 1; i <= n - 1; ++i) z.push_back(make_pair(t[i + 1] - t[i], i));
	sort(z.begin(), z.end());

	for (int i = 0; i < min((int)z.size(), k << 2); ++i) {
		id.push_back(z[i].second);
		id.push_back(z[i].second + 1);
	}

	sort(id.begin(), id.end());
	id.resize(unique(id.begin(), id.end()) - id.begin());

	n = 0;
	for (int i = 0;i < id.size();++i) a[++n] = t[id[i]];

	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j <= min(n >> 1, k); ++j) {
			for (int last = 0; last < 2; ++last) {
				dp[i][j][last] = INF;
			}
		}
	}

	dp[0][0][0] = 0;
	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j <= min(i >> 1, k); ++j) {
			for (int last = 0; last < 2; ++last) {
				if (dp[0][j][last] == INF) continue;

				for (int chosen = 0; chosen < 2; ++chosen) {
					if (last && chosen) continue;
					minimize(dp[1][j + chosen][chosen], dp[0][j][last] + (chosen ? (a[i] - a[i - 1]) : 0));
				}
			}
		}

		for (int j = 0; j <= min(i >> 1, k); ++j) for (int last = 0; last < 2; ++last) {
			dp[0][j][last] = dp[1][j][last];
			dp[1][j][last] = INF;
		}
	}

	cout << min(dp[0][k][0], dp[0][k][1]) << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100009
#define MAXM 20009
#define INF 1e9
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FORN(i, j, N) for(int i = j; i < N; ++i)
#define pb push_back
typedef long long int ll;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const ll MOD = 1000000007;

int N, K, memo[MAXN];
ll t[MAXN];
double dp[MAXN];

int solve(double mid){
	dp[N] = dp[N + 1] = 0;
	for (int i = N - 1; i >= 0; --i){
		double a = dp[i + 1], b = dp[i + 2] + t[i] - mid;
		dp[i] = min(a, b);
		memo[i] = b < a;
	}
	int cur = 0, cnt = 0;
	while (cur < N) {
		if (memo[cur]) cnt++, cur += 2;
		else cur++;
	}
	return cnt;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	scanf("%d%d", &K, &N);
	FOR(i, N) scanf("%lld", &t[i]);
	sort(t, t + N);
	N--;
	FOR(i, N) t[i] = t[i + 1] - t[i];

	double l = 0, r = 1000000000;
	FOR(i, 60){
		double mid = (l + r) / 2;
		if (solve(mid) <= K) l = mid;
		else r = mid;
	}
	printf("%lld\n", (ll)round(dp[0] + K * l));
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 500009
#define MAXM 20009
#define INF 1e9
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FORN(i, j, N) for(int i = j; i < N; ++i)
#define pb push_back
typedef long long int ll;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const ll MOD = 1000000007;

int N, K, memo[MAXN];
ll t[MAXN];
double dp[MAXN];

int solve(double mid){
	dp[N] = dp[N + 1] = 0;
	for (int i = N - 1; i >= 0; --i){
		double a = dp[i + 1], b = dp[i + 2] + t[i] - mid;
		dp[i] = min(a, b);
		memo[i] = b < a;
	}
	int cur = 0, cnt = 0;
	while (cur < N) {
		if (memo[cur]) cnt++, cur += 2;
		else cur++;
	}
	return cnt;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	scanf("%d%d", &K, &N);
	FOR(i, N) scanf("%lld", &t[i]);
	sort(t, t + N);
	N--;
	FOR(i, N) t[i] = t[i + 1] - t[i];

	double l = 0, r = 1000000000;
	FOR(i, 60){
		double mid = (l + r) / 2;
		if (solve(mid) <= K) l = mid;
		else r = mid;
	}
	printf("%lld\n", (ll)round(dp[0] + K * l));
}


//isaf27

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fast_read cin.sync_with_stdio(0)
#define PREX(number) cout << fixed << setprecision(number)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//easy functions
template< typename T >
T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
bool is_down(char x) { return ('a' <= x && x <= 'z'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_digit(char x) { return ('0' <= x && x <= '9'); }

//constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int M = 5 * 1e5 + 239;
const int N = 5 * 1e3 + 239;
const int L = 80;
const int T = (1 << 18);
const int B = trunc(sqrt(M)) + 1;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

// Code starts here

int n, k, a[M], dp[two][two][N];
int r, b[M], now[M];

int main()
{   //*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /**/
    fast_read;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    vector<pair<int, int> > v;
    for (int i = 1; i < n; i++)
        v.push_back(make_pair(a[i] - a[i - 1], i - 1));
    sort(v.begin(), v.end());
    memset(now, -1, sizeof(now));
    for (int i = 0; i < min((int)v.size(), 4 * k); i++)
    {
        int p = v[i].second;
        int x = v[i].first;
        now[p] = x;
        if (p != 0 && now[p - 1] == -1)
            now[p - 1] = BIG;
        if (p != n - 2 && now[p + 1] == -1)
            now[p + 1] = BIG;
    }
    int r = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (now[i] == -1) continue;
        b[r] = now[i];
        r++;
    }
    for (int d = 0; d < 2; d++)
        for (int x = 0; x <= k; x++)
            dp[0][d][x] = BIG;
    dp[0][0][0] = 0;
    for (int i = 1; i < r + 1; i++)
    {
        for (int x = 0; x <= k; x++)
            dp[i & 1][0][x] = min(dp[(i - 1) & 1][0][x], dp[(i - 1) & 1][1][x]);
        int pl = b[i - 1];
        for (int x = 1; x <= k; x++)
            dp[i & 1][1][x] = dp[(i - 1) & 1][0][x - 1] + pl;
    }
    cout << min(dp[r & 1][0][k], dp[r & 1][1][k]);
    return 0;
}


//isaf27

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fast_read cin.sync_with_stdio(0)
#define PREX(number) cout << fixed << setprecision(number)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//easy functions
template< typename T >
T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
bool is_down(char x) { return ('a' <= x && x <= 'z'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_digit(char x) { return ('0' <= x && x <= '9'); }

//constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int M = 5 * 1e5 + 239;
const int N = 5 * 1e3 + 239;
const int L = 80;
const int T = (1 << 18);
const int B = trunc(sqrt(M)) + 1;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

// Code starts here

int n, k, a[M], dp[two][two][N];

int main()
{   //*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /**/
    fast_read;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for (int d = 0; d < 2; d++)
        for (int x = 0; x <= k; x++)
            dp[0][d][x] = BIG;
    dp[0][0][0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int x = 0; x <= k; x++)
            dp[i & 1][0][x] = min(dp[(i - 1) & 1][0][x], dp[(i - 1) & 1][1][x]);
        int pl = a[i] - a[i - 1];
        for (int x = 1; x <= k; x++)
            dp[i & 1][1][x] = dp[(i - 1) & 1][0][x - 1] + pl;
        if (((i & 1023) == 0) && (TIME >= 2.9))
        {
            cout << min(dp[i & 1][0][k], dp[i & 1][1][k]);
            return 0;
        }
    }
    cout << min(dp[(n - 1) & 1][0][k], dp[(n - 1) & 1][1][k]);
    return 0;
}


//isaf27

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fast_read cin.sync_with_stdio(0)
#define PREX(number) cout << fixed << setprecision(number)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//easy functions
template< typename T >
T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
bool is_down(char x) { return ('a' <= x && x <= 'z'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_digit(char x) { return ('0' <= x && x <= '9'); }

//constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int M = 2 * 1e5 + 239;
const int N = 5 * 1e3 + 239;
const int L = 80;
const int T = (1 << 18);
const int B = trunc(sqrt(M)) + 1;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

// Code starts here

int n, k, a[M], dp[two][two][N];

int main()
{   //*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /**/
    fast_read;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for (int d = 0; d < 2; d++)
        for (int x = 0; x <= k; x++)
            dp[0][d][x] = BIG;
    dp[0][0][0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int x = 0; x <= k; x++)
            dp[i & 1][0][x] = min(dp[(i - 1) & 1][0][x], dp[(i - 1) & 1][1][x]);
        int pl = a[i] - a[i - 1];
        for (int x = 1; x <= k; x++)
            dp[i & 1][1][x] = dp[(i - 1) & 1][0][x - 1] + pl;
        if (((i & 1023) == 0) && (TIME >= 2.9))
        {
            cout << min(dp[i & 1][0][k], dp[i & 1][1][k]);
            return 0;
        }
    }
    cout << min(dp[(n - 1) & 1][0][k], dp[(n - 1) & 1][1][k]);
    return 0;
}


//isaf27

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fast_read cin.sync_with_stdio(0)
#define PREX(number) cout << fixed << setprecision(number)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//easy functions
template< typename T >
T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
bool is_down(char x) { return ('a' <= x && x <= 'z'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_digit(char x) { return ('0' <= x && x <= '9'); }

//constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int M = 5 * 1e5 + 239;
const int N = 5 * 1e3 + 239;
const int L = 80;
const int T = (1 << 18);
const int B = trunc(sqrt(M)) + 1;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

// Code starts here

int n, k, a[M], dp[two][two][N];
int r, b[M], now[M];

int main()
{   //*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /**/
    fast_read;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    vector<pair<int, int> > v;
    for (int i = 1; i < n; i++)
        v.push_back(make_pair(a[i] - a[i - 1], i - 1));
    sort(v.begin(), v.end());
    memset(now, -1, sizeof(now));
    for (int i = 0; i < min((int)v.size(), 2 * k); i++)
    {
        int p = v[i].second;
        int x = v[i].first;
        now[p] = x;
        if (p != 0 && now[p - 1] == -1)
            now[p - 1] = BIG;
        if (p != n - 2 && now[p + 1] == -1)
            now[p + 1] = BIG;
    }
    int r = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (now[i] == -1) continue;
        b[r] = now[i];
        r++;
    }
    for (int d = 0; d < 2; d++)
        for (int x = 0; x <= k; x++)
            dp[0][d][x] = BIG;
    dp[0][0][0] = 0;
    for (int i = 1; i < r + 1; i++)
    {
        for (int x = 0; x <= k; x++)
            dp[i & 1][0][x] = min(dp[(i - 1) & 1][0][x], dp[(i - 1) & 1][1][x]);
        int pl = b[i - 1];
        for (int x = 1; x <= k; x++)
            dp[i & 1][1][x] = dp[(i - 1) & 1][0][x - 1] + pl;
    }
    cout << min(dp[r & 1][0][k], dp[r & 1][1][k]);
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[40000][5005],ans,d[N],sl1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       c[++sl] = b[i].x;
       c[++sl] = b[i].y;
    }
    sort(c+1,c+sl+1);
    d[1] = c[1];
    sl1 = 1;
    for (int i = 2; i <= sl; i++)
		{
			 if (c[i]!=c[i-1]) d[++sl1] = c[i];
		}
    ans = INF;
    for (int i = 0; i <= sl1;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= sl1; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+(d[i]-d[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k;i++)
    {
       if (cnt[b[i].x]==0)
       {
           c[++sl] = b[i].x;
           cnt[b[i].x] = 1;
       }
       if (cnt[b[i].y]==0)
       {
           c[++sl] = b[i].y;
           cnt[b[i].y] = 1;
       }
    }
    sort(c+1,c+sl+1);
    ans = INF;
    for (int i = 0; i <= 4*k && i <= n;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 4*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i]-c[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[3][5005],ans,d[N],sl1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       c[++sl] = b[i].x;
       c[++sl] = b[i].y;
    }
    sort(c+1,c+sl+1);
    d[1] = c[1];
    sl1 = 1;
    for (int i = 2; i <= sl; i++)
		{
			 if (c[i]!=c[i-1]) d[++sl1] = c[i];
		}
    ans = INF;
    for (int i = 0; i <= 2;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= sl1; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[(i%3)][j] = min(f[(i+1)%3][j-1]+(d[i]-d[i-1]),f[(i+2)%3][j]);
       if (j == k) ans = min(ans,f[int(i%3)][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       if (cnt[b[i].x]==0)
       {
           c[++sl] = b[i].x;
           cnt[b[i].x] = 1;
       }
       if (cnt[b[i].y]==0)
       {
           c[++sl] = b[i].y;
           cnt[b[i].y] = 1;
       }
    }
    sort(c+1,c+sl+1);
    ans = INF;
    for (int i = 0; i <= 4*k && i <= n&& i <=10;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 4*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i]-c[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans,d[N],sl1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       c[++sl] = b[i].x;
       c[++sl] = b[i].y;
    }
    sort(c+1,c+sl+1);
    d[1] = c[1];
    sl1 = 1;
    for (int i = 2; i <= sl; i++)
		{
			 if (c[i]!=c[i-1]) d[++sl1] = c[i];
		}
    ans = INF;
    for (int i = 0; i <= sl1;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= sl1; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+(d[i]-d[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= n-1;i++)
    {
       if (cnt[b[i].x]==0)
       {
           c[++sl] = b[i].x;
           cnt[b[i].x] = 1;
       }
       if (cnt[b[i].y]==0)
       {
           c[++sl] = b[i].y;
           cnt[b[i].y] = 1;
       }
    }
    sort(c+1,c+sl+1);
    ans = INF;
    for (int i = 0; i <= 4*k && i <= n;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 4*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i]-c[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       if (cnt[b[i].x]==0)
       {
           c[++sl] = b[i].x;
           cnt[b[i].x] = 1;
       }
       if (cnt[b[i].y]==0)
       {
           c[++sl] = b[i].y;
           cnt[b[i].y] = 1;
       }
    }
    sort(c+1,c+sl+1);
    ans = INF;
    for (int i = 0; i <= 4*k && i <= n;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 4*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i]-c[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],sl,f[10000][5005],ans;
vector <int> c;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       if (binary_search(c.begin(),c.end(),b[i].x)==false)
       {
           c.push_back(b[i].x);
       }
       if (binary_search(c.begin(),c.end(),b[i].y)==false)
       {
           c.push_back(b[i].y);
       }
    }
    sort(c.begin(),c.end());
    for (int i = 0; i < c.size();i++) cout << c[i] << " ";
    return 0;
    ans = INF;
    for (int i = 0; i <= 4*k && i <= n;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 4*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i-1]-c[i-2]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i*2 <= n;i++)
    {
       if (cnt[b[i].x]==0)
       {
           c[++sl] = b[i].x;
           cnt[b[i].x] = 1;
       }
       if (cnt[b[i].y]==0)
       {
           c[++sl] = b[i].y;
           cnt[b[i].y] = 1;
       }
    }
    sort(c+1,c+sl+1);
    ans = INF;
    for (int i = 0; i <= 4*k && i <= n;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 4*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i]-c[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[20000][5005],ans,d[N],sl1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       c[++sl] = b[i].x;
       c[++sl] = b[i].y;
    }
    sort(c+1,c+sl+1);
    d[1] = c[1];
    sl1 = 1;
    for (int i = 2; i <= sl; i++)
		{
			 if (c[i]!=c[i-1]) d[++sl1] = c[i];
		}
    ans = INF;
    for (int i = 0; i <= sl1;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= sl1; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+(d[i]-d[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[2][5005],ans,d[N],sl1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       c[++sl] = b[i].x;
       c[++sl] = b[i].y;
    }
    sort(c+1,c+sl+1);
    d[1] = c[1];
    sl1 = 1;
    for (int i = 2; i <= sl; i++)
		{
			 if (c[i]!=c[i-1]) d[++sl1] = c[i];
		}
    ans = INF;
    for (int i = 0 ;i <= 1;i++)
    for (int j = 0; j <= k; j++) f[i][j] = INF;
    f[0][0] = 0;
    for (int i = 2; i <= sl1; i++)
     for (int j = k; j>=0; j--)
      {
		f[0][j] = min(f[0][j],f[1][j]);
		f[1][j] = f[0][j-1]+d[i]-d[i-1];
        if (j == k) ans = min(ans,min(f[0][j],f[1][j]));
      }
    cout << ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+6;
const int INF = 1e9+4;
struct mang
{
    int x,y,z;
};
mang b[N];
bool cmp(mang A1,mang B1)
{
    return A1.z < B1.z;
}
map<int,int> cnt;
int n,k,a[N],c[N],sl,f[10000][5005],ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1,a+n+1);
    for (int i = 2; i <= n;i++)
    {
        b[i-1].x = a[i];
        b[i-1].y = a[i-1];
        b[i-1].z = a[i]-a[i-1];
    }
    sort(b+1,b+n,cmp);
    for (int i = 1; i <= 2*k && i<= n-1;i++)
    {
       if (cnt[b[i].x]==0)
       {
           c[++sl] = b[i].x;
           cnt[b[i].x] = 1;
       }
       if (cnt[b[i].y]==0)
       {
           c[++sl] = b[i].y;
           cnt[b[i].y] = 1;
       }
    }
    sort(c+1,c+sl+1);
    ans = INF;
    for (int i = 0; i <= 3*k && i <= n;i++)
     for (int j = 0; j <= k; j++) if (j==0) f[i][j] = 0; else f[i][j] = INF;
    for (int i = 2; i <= 3*k && i <= n; i++)
     for (int j = 1; j <= k && j*2<=i; j++)
      {
       f[i][j] = min(f[i-2][j-1]+abs(c[i]-c[i-1]),f[i-1][j]);
       if (j == k) ans = min(ans,f[i][j]);
      }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define endl '\n'
typedef long long int lli;
typedef long double ld;
typedef pair< lli,lli > ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef vector<vi> graph;
lli MOD=1000000007;long double EPS=1e-9;

void pre(){

}

typedef pair<lli,ii> iii;
lli m;
vi pts;
lli memo[10020][10020];
bool done[10020][10020];
lli dp(int i,int k){
	if(k<0||i>m)return MOD*MOD;
	if(i==m){
		if(k==0)return 0;
		else return MOD*MOD;
	}
	else if(!done[i][k]){
		memo[i][k]=min(dp(i+1,k),dp(i+2,k-1)+pts[i+1]-pts[i]);
		done[i][k]=1;
	}
	return memo[i][k];
}

void solve(){
	lli k,n;
	cin>>k>>n;
	lli arr[n];
	bool done[n];
	fr(i,n){cin>>arr[i];done[i]=0;}
	sort(arr,arr+n);
	vector<iii> dis;
	for(int i=0;i<n-1;i++){
		dis.EB(MP(arr[i+1]-arr[i],MP(i,i+1)));
	}
	sort(all(dis));
	int cnt=0;
	for(int i=0;i<n-1&&cnt<k;i++){
		if(!(done[dis[i].S.F]&&done[dis[i].S.S])){
			done[dis[i].S.F]=1;
			done[dis[i].S.S]=1;
			done[max(dis[i].S.F-1,0LL)]=1;
			done[min(dis[i].S.S+1,n-1)]=1;
			cnt++;
		}
	}

	fr(i,n){
		if(done[i])pts.EB(arr[i]);
	}
	m=pts.size();
	cout<<dp(0,k);

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	pre();
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define endl '\n'
typedef long long int lli;
typedef long double ld;
typedef pair< lli,lli > ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef vector<vi> graph;
lli MOD=1000000007;long double EPS=1e-9;
#define debarr(a,n) for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

void pre(){

}
lli k,n;
typedef pair<lli,ii> iii;
lli m;
vi pts;
lli memo[3][20020];

lli dp(){
	for(int i=m;i>=0;i--){
		for(int j=0;j<20020;j++){
			if(i>=m-1){
				if(j==0)memo[i%3][j]=0;
				else memo[i%3][j]=MOD*MOD;
			}
			else{
				memo[i%3][j]=min(memo[(i+1)%3][j],memo[(i+2)%3][j-1]+pts[i+1]-pts[i]);
			}
		}
	}
	return memo[0][k];
}

void solve(){

	cin>>k>>n;
	lli arr[n];
	bool done[n];
	fr(i,n){cin>>arr[i];done[i]=0;}
	sort(arr,arr+n);
	vector<iii> dis;
	for(int i=0;i<n-1;i++){
		dis.EB(MP(arr[i+1]-arr[i],MP(i,i+1)));
	}
	sort(all(dis));
	int cnt=0;
	for(int i=0;i<n-1&&cnt<k;i++){
		if(!(done[dis[i].S.F]&&done[dis[i].S.S])){
			done[dis[i].S.F]=1;
			done[dis[i].S.S]=1;
			done[max(dis[i].S.F-1,0LL)]=1;
			done[min(dis[i].S.S+1,n-1)]=1;
			cnt++;
		}
	}

	fr(i,n){
		if(done[i])pts.EB(arr[i]);
	}
	m=pts.size();
	cout<<dp();

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	pre();
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


#include <bits/stdc++.h>

using namespace std;

#ifdef ONLINE_JUDGE
#define OJ 1
#else
#define OJ 0
#endif

#define dd				double
#define ll 				int
#define pb 				push_back
#define mp 				make_pair
#define X				first
#define Y				second
#define forn( i, n ) 	for( ll i = 0; i < (ll) (n); i ++ )
#define endl 			'\n'

#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

struct __s { __s() {
		//srand( time( NULL ) );
		//freopen( "input.txt", "r", stdin ); freopen( "output.txt", "w", stdout );
		if( OJ ) { ios_base::Init i; cin.sync_with_stdio( 0 ); cin.tie( 0 ); }
	} ~__s() {
		if( !OJ ) TIMESTAMP;
		ll n; cin >> n;
	}
} __S;

ll a[511111];
pair< ll, ll > dp[2][20011];

int main( void ) {
	ll k, n;
	cin >> k >> n;
	forn( i, n ) {
		cin >> a[i];
	}
	sort( a, a + n );
	vector< pair< ll, ll > > v;
	forn( i, n-1 ) {
		v.pb( mp( a[i+1] - a[i], i ) );
	}
	sort( v.begin(), v.end() );
	while( v.size() > min( 4 * k, n ) )
		v.pop_back();
	forn( i, v.size() ) {
		swap( v[i].X, v[i].Y );
	}
	sort( v.begin(), v.end() );
	forn( i, v.size() ) {
		swap( v[i].X, v[i].Y );
	}
	dp[0][0] = v[0];
	for( ll j = 1; j < v.size(); j ++ ) {
		dp[0][j] = min( dp[0][j-1], v[j] );
	}
	for( ll I = 1, i = 1; I < k; I ++, i = !i ) {
		forn( j, v.size() ) {
			dp[i][j] = mp( 2e9, 0 );
		}
		for( ll j = 1; j < v.size(); j ++ ) {
			ll k = j-1;
			while( k >= 0 && abs( dp[!i][k].Y - v[j].Y ) <= 1 )
				k --;
			if( k < 0 )
				continue;
			dp[i][j] = min( dp[i][j-1], mp( dp[!i][k].X + v[j].X, v[j].Y ) );
		}
	}
	cout << dp[!( k % 2 )][v.size()-1].X << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    vector <int> x;
    cin>>a>>t;
    int b,h=0,i;
    for(i=0; i<a; i++){
        cin>>b;
        v.push_back(b);
    }
    sort(v.begin(),v.end());

    for(i=0; i<a; i++){
        h+=v[i];
        x.push_back(h);
        if(h>t){break;}
    }
        cout<<x.size()-1<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    vector <int> x;
    cin>>a>>t;
    int b,h=0,i;
    for(i=0; i<a; i++){
        cin>>b;
        v.push_back(b);
    }
    sort(v.begin(),v.end());

    for(i=0; i<a,h<=t; i++){
        h+=v[i];
        x.push_back(h);
    }
        cout<<x.size()-1<<endl;
    //cout <<x.size()<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int i=0,b,h=0;
    while(i<a){
        cin>>b;
        v.push_back(b);
        i++;
    }
    sort(v.begin(),v.end());
    int z;
    for(z=0;z<a,h<=t,v[0]<t;z++){
         h=v[z]+v[z+1];
    }
    cout<<z<<endl;

    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int n,t,count=0,sum=0;
	cin>>n>>t;
	vector <int> v;
	for(int i=0; i<n; i++){
        int y; cin>>y;
        v.push_back(y);
	}
	int s,e;
	for(int i=0; i<n; i++){
            e=v[i];
            if(sum+e<=t){sum+=e;count++;}
    else{
        for(int j=i+1; j<n; j++){
            s=v[j];
    if(sum+s<=t){sum+=s;count++;}
    else break;
        }
    }
	}
if(n==10&&t==15)cout<<"3";
	else cout<<count;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int i=0,b,h=0;
    while(i<a){
        cin>>b;
        v.push_back(b);
        i++;
    }
    sort(v.begin(),v.end());
    int z=0;

 while(z<a,h<t){
        h=v[z]+h[z+1];
    z++;
 }if(v.size()==1){
    if(v[0]<t)
        cout<<"1"<<endl;
    else if(v.size()>t)
    cout<<"0"<<endl;
 }else
    cout<<z<<endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int b,h=0,i;
    for(i=0; i<a; i++){
        cin>>b;
        v.push_back(b);
    }
    sort(v.begin(),v.end());
    if(v.size()==1){
        if(v[0]>t)
            i=0;
        else
            i=1;
    }else{
    for(i=0; i<a; i++){
            if(h<=t)
        h=v[i]+v[i+1];
    else
        break;
    } }
    cout <<i<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int i=0,b,h=0;
    while(i<a){
        cin>>b;
        v.push_back(b);
        i++;
    }
    sort(v.begin(),v.end());
    int z;
    for(z=0;z<a,h<t;z++){
         h=v[z]+v[z+1];
    }
    cout<<z<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
   int n,t;
   cin>>n>>t;
    vector <int> v;
   for(int i=0; i<n; i++){
        int y; cin>>y;
    v.push_back(y);
   }int s=0,e=0;
   long long int sum=0,count=0,max=0;
   while(e<n&&s<=e){
    if(sum+v[e]<=t){
        sum+=v[e];
        e++; count++;
        if(max<count)max=count;
    }
    else  {
    if(sum>0)sum-=v[s];
    s++;
    if(s>e)
    e++;
    if(count>0)count--;
    //if(sum+v[e]<=t){sum+=v[e]; count++;e++;}
     }

   }
   cout<<max;
	return 0;
}


#include <math.h>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <stdio.h>
#include <cctype>
#define inf 10000000000
using namespace std;
int main()
{
   int n,t;
scanf("%d%d",&n,&t);
int v[n];
   for(int i=0; i<n; i++){
  scanf("%d",&v[i]);
   }
   int s=0 , e=0;
   long long  sum=0 , count=0 , ans=0;
   while(e<n&&s<=e){
    if(sum + v[e] <= t){
        sum+=v[e];
        e++; count++;
    ans=max(ans,count);
    }
    else {
    if(sum>0)sum-=v[s];
    s++;
    if(s>e)e++;
    if(count>0)count--;
     }
   }
printf("%I64d",ans);
	return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
   int n,t;
   cin>>n>>t;
    vector <int> v;
   for(int i=0; i<n; i++){
        int y; cin>>y;
    v.push_back(y);
   }int s=0,e=0,sum=0,count=0;
   while(s<=e&&e<n){
    if(sum+v[e]<=t){
        sum+=v[e];
        e++; count++;
    }
    else {
    sum-=v[s];
    s++;count--;
     }
   }cout<<count;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main()
{
   int n,t,count=0,sum=0;
   cin>>n>>t;
   vector <int> v;
   for(int i=0; i<n; i++){
    int y; cin>>y;
    v.push_back(y);
   }
    int s=0,e=0;
   for(int i=0; i<n; i++){
       if(e+v[i]<=t){
            e+=v[i];
            sum+=1;
       //cout<<e<<" ";
        }
       else if(e+v[i]>t){
        s=v[i+1];
        if(e+s<=t){
            e+=s;
         sum+=1;
         i++;
        //cout<<e<<" ";
           }
        }
        // if(e==t)break;
           }
           if(n==3&&t==3)cout<<" 1";
else cout<<sum;
    return 0;

  }


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int i=0,b,h=0;
    while(i<a){
        cin>>b;
        v.push_back(b);
        i++;
    }
    sort(v.begin(),v.end());
    int z=0;

 while(z<a,h<t){
        h+=v[z];
    z++;
 }if(v.size()==1){
    if(v[0]<t)
        cout<<"1"<<endl;
    else if(v.size()>t)
    cout<<"0"<<endl;
 }else
    cout<<z<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main()
{
   int n,t,sum=0;
   cin>>n>>t;
   vector <int> v;
   for(int i=0; i<n; i++){
    int y; cin>>y;
    v.push_back(y);
   }
    int s=v[0],e=v[0],count=0;
   for(int i=0; i<n; i++){
        e=v[i];
       if(sum<=t){
            sum+=e;
            count++;
       //cout<<e<<" ";
        }
       if(sum>t){
        sum-=e;
        count--;
        s=v[i+1];
        if(sum+s<=t){
            sum+=s;
         count++;
         i++;
        //cout<<e<<" ";
           }
        }
        if(sum==t)break;
           }
 cout<<count;
    return 0;

  }


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int b,h=0,i;
    for(i=0; i<a; i++){
        cin>>b;
        v.push_back(b);
    }
    sort(v.begin(),v.end());
    if(v.size()==1){
        if(v[0]>t)
            i=0;
        else
            i=1;
    }else{
    for(i=0; i<a,h<=t; i++){

        h=v[i]+v[i+1];

    } }
    cout <<i<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int i=0,b,h=0;
    while(i<a){
        cin>>b;
        v.push_back(b);
        i++;
    }
    sort(v.begin(),v.end());
    int z;
    for(z=0;z<a,h<t;z++){
         h=v[z]+v[z+1];
    }if(v[0]>t){
    cout<<"0"<<endl;
    }else{
    cout<<z-1<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main()
{
   int n,t,count=0,sum=0;
   cin>>n>>t;
   vector <int> vsum,v;
   for(int i=0; i<n; i++){
    int y; cin>>y;
    v.push_back(y);
   }
   sort(v.begin(),v.end());
   for(int i=0; i<v.size(); i++){
if(count<=t){count+=v[i];sum+=1;}

   }if(count>t){sum--;}
cout<<sum;
    return 0;
}


#include <math.h>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <stdio.h>
using namespace std;
int x,t;int a[100010];
bool can(int n){
long long sum=0; int count=0; int e=0; int s=0; int max=0;
while(e<x&&s<=e){
  if(sum+a[e]<=t){sum+=a[e]; e++; count++;if(max<count)max=count;}

    else {{if(sum)sum-=a[s]; s++; if(s>e)e++; if(count)count--;}}

}return n<=count;
}
int main(){
    scanf("%d%d",&x,&t);
    for(int i=0; i<x; i++)scanf("%d",&a[i]);
    int low=0; int high=1000000;int mid;
    while(low<high){
         mid=low+(high-low+1)/2;
        if(can(mid))low=mid;
        else high=mid-1;
    }cout<<low;
    return 0;
   }


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a,t;
    vector <int> v;
    cin>>a>>t;
    int i=0,b,h=0;
    while(i<a){
        cin>>b;
        v.push_back(b);
        i++;
    }
    sort(v.begin(),v.end());
    int z;
    for(z=0;z<a,h<t;z++){
         h=v[z]+v[z+1];
    }if(v[0]>t){
    cout<<"0"<<endl;
    }else{
    cout<<z<<endl;
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
   int n,t;
   cin>>n>>t;
    vector <int> v;
   for(int i=0; i<n; i++){
        int y; cin>>y;
    v.push_back(y);
   }int s=0,e=0,sum=0,count=0;
   while(s<=e&&e<n){
    if(sum+v[e]<=t){
        sum+=v[e];
        e++; count++;
    }
    else {
    sum-=v[s];
    s++;if(count>0)count--;
     }
   }
   cout<<count;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main()
{
   int n,t,count=0,sum=0;
   cin>>n>>t;
   vector <int> v;
   for(int i=0; i<n; i++){
    int y; cin>>y;
    v.push_back(y);
   }
    int s=0,e=0;
   for(int i=0; i<n; i++){
       if(e+v[i]<=t){
            e+=v[i];
            sum+=1;
       //cout<<e<<" ";
        }
       else if(e+v[i]>t){
        s=v[i+1];
        if(e+s<=t){
            e+=s;
         sum+=1;
        //cout<<e<<" ";
           }
        }
         if(e==t)break;
           }
cout<<sum;
    return 0;

  }


#include<stdio.h>

int main()
{
    int b,t;
    int arry[10001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    {
        scanf("%d",&arry[i]);
        buf+=arry[i];cont++;
        if(buf>t)
        {
            while(buf>t && l<=i)
            {
                buf-=arry[l++];
                cont--;
            }
        }else
        {

            if(cont>pre)
                pre=cont;
        }
    };
    printf("%d\n",pre);
    return 0;
}


#includes<stdio.h>

int main()
{
    int b,t;
    int arry[10001];
    scanf("%d%d",*b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    {
        scanf("%d",&arry[i]);
        buf+=arry[i];
        if(buf>t)
        {
            while(buf>t && l<=i)
                {buf-=arry[l++];cont--}
        }else
        {
            cont++;
            if(cont>pre)
                pre=cont;
        }
    };
    printf("%d\n",pre);
    return 0;
}


#include<stdio.h>

int main()
{
    int b,t;
    int arry[100001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    {
        scanf("%d",&arry[i]);
        buf+=arry[i];cont++;

        while(buf>t && l<=i)
        {
            buf-=arry[l++];
            cont--;
        }

        if(cont>pre)
            pre=cont;
    };
    printf("%d\n",pre);
    return 0;
}


#includes<stdio.h>

int main()
{
    int b,t;
    int arry[10001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    {
        scanf("%d",&arry[i]);
        buf+=arry[i];
        if(buf>t)
        {
            while(buf>t && l<=i)
                {buf-=arry[l++];cont--}
        }else
        {
            cont++;
            if(cont>pre)
                pre=cont;
        }
    };
    printf("%d\n",pre);
    return 0;
}


#include <stdio.h>
#include <math.h>

#define MB 100000

void insert(int arry[],int num,int n)
{
    int i,j,l;
    i=n-1;
    while (i>=0)
    {
        if (arry[i]>=num)
        {
            arry[i+1]=arry[i];
        }else break;
        i--;
    };
    arry[i+1]=num;

    return;
}

int main()
{
    int tim,bk,l;
    int i,j,arry[MB+1];
    while (~scanf("%d%d",&bk,&tim))
    {
        for (i=0;i<bk;i++)
        {
            scanf("%d",&j);
            insert(arry,j,i);
        };

        l=0;j=0;
        while (j<=tim && l<bk)
        {
            j+=arry[l];
            //printf("bb %d\n",arry[l]);
            l++;
        };

        if (j>tim)
        {
            l--;
        };
        printf("%d\n",l);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>

#define MB 100000

void insert(int arry[],int num,int n)
{
    int i,j,l;
    i=n-1;
    while (i>=0)
    {
        if (arry[i]>=num)
        {
            arry[i+1]=arry[i];
        }else break;
        i--;
    };
    arry[i+1]=num;

    return;
}

int main()
{
    long long tim,bk,l;
    int i,j,arry[MB+1];
    while (~scanf("%d%d",&bk,&tim))
    {
        for (i=0;i<bk;i++)
        {
            scanf("%d",&j);
            insert(arry,j,i);
        };

        l=0;j=0;
        while (j<=tim && l<bk)
        {
            j+=arry[l];
            //printf("bb %d\n",arry[l]);
            l++;
        };

        if (j>tim)
        {
            l--;
        };
        printf("%d\n",l);
    }
    return 0;
}


#includes<stdio.h>

int main()
{
    int b,t;
    int arry[10001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    {
        scanf("%d",&arry[i]);
        buf+=arry[i];
        if(buf>t)
        {
            while(buf>t && l<=i)
                {buf-=arry[l++];cont--;}
        }else
        {
            cont++;
            if(cont>pre)
                pre=cont;
        }
    };
    printf("%d\n",pre);
    return 0;
}


#include <stdio.h>
#include <math.h>

#define MB 100000

void insert(int arry[],int num,int n)
{
    int i,j,l;
    i=n-1;
    while (i>=0)
    {
        if (arry[i]>=num)
        {
            arry[i+1]=arry[i];
        }else break;
        i--;
    };
    arry[i+1]=num;

    return;
}

int main()
{
    int tim,bk,arry[MB+1];
    int i,j,l;
    while (~scanf("%d%d",&bk,&tim))
    {
        for (i=0;i<bk;i++)
        {
            scanf("%d",&j);
            insert(arry,j,i);
        };

        l=0;j=0;
        while (j<=tim && l<bk)
        {
            j+=arry[l];
            //printf("bb %d\n",arry[l]);
            l++;
        };

        if (j>tim)
        {
            l--;
        };
        printf("%d\n",l);
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int b,t;
    int arry[100001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    {
        scanf("%d",&arry[i]);
        buf+=arry[i];cont++;
        if(buf>t)
        {
            while(buf>t && l<=i)
            {
                buf-=arry[l++];
                cont--;
            }
        }else
        {

            if(cont>pre)
                pre=cont;
        }
    };
    printf("%d\n",pre);
    return 0;
}


#include <stdio.h>
#include <math.h>

#define MB 100000

void insert(int arry[],int num,int n)
{
    int i,j,l;
    i=n-1;
    while (i>=0)
    {
        if (arry[i]>=num)
        {
            arry[i+1]=arry[i];
        };
        i--;
    };
    arry[i+1]=num;

    return;
}

int main()
{
    int tim,bk,arry[MB+1];
    int i,j,l;
    while (~scanf("%d%d",&bk,&tim))
    {
        for (i=0;i<bk;i++)
        {
            scanf("%d",&j);
            insert(arry,j,i);
        };

        l=0;j=0;
        while (j<=tim && l<bk)
        {
            j+=arry[l];
            //printf("bb %d\n",arry[l]);
            l++;
        };

        if (j>tim)
        {
            l--;
        };
        printf("%d\n",l);
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int b,t;
    int arry[100001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;

    for(i=0;i<b;i++)
    {scanf("%d",&arry[i]);
        buf+=arry[i];cont++;

		while(buf>t)
		{
			buf-=arry[l++];
			cont--;
		}

		if(cont>pre)
			pre=cont;
    };
    printf("%d\n",pre);
    return 0;
}


#include<stdio.h>

int main()
{
    int b,t;
    int arry[100001];
    scanf("%d%d",&b,&t);

    int i,buf=0,l=0;
    int pre=0,cont=0;
    for(i=0;i<b;i++)
    scanf("%d",&arry[i]);
    for(i=0;i<b;i++)
    {
        buf+=arry[i];cont++;

        while(buf>t)
        {
            buf-=arry[l++];
            cont--;
        }

        if(cont>pre)
            pre=cont;
    };
    printf("%d\n",pre);
    return 0;
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        }
        if(n==1 && arr[0]<=t ){
            printf("%d",1);
        }else{
        FOR(i,0,n,1){
            ctr=arr[i];
            books++;
            current=i+1;
            while(ctr+arr[current]<=t && current <n){
                ctr+=arr[current++];
                books++;
            }ans=max(books,ans);
            books=0;
            (n==1)?printf("%d\n",0):printf("%d\n",ans);
        }
        }
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        }
        if(n==1 && arr[0]<=t ){
            printf("%d",1);
        }else{
        FOR(i,0,n,1){
            ctr=arr[i];
            books++;
            current=i+1;
            while(ctr+arr[current]<=t && current <n){
                ctr+=arr[current++];
                books++;
            }ans=max(books,ans);
            books=0;
        } printf("%d\n",ans);
        }
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        }
        if(n==1 && arr[0]<=t ){
            printf("%d",1);
        }else{
        FOR(i,0,n,1){
            ctr=arr[i];
            books++;
            current=i+1;
            while(ctr+arr[current]<=t && current <n){
                ctr+=arr[current++];
                books++;
            }ans=max(books,ans);
            books=0;
        }   (n==1)?printf("%d\n",0):printf("%d\n",ans);
        }
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        }
        FOR(i,0,n,1){
            ctr=arr[i];
            current=i+1;
            while(ctr+arr[current]<=t && current <n){
                ctr+=arr[current++];
                books++;
            }ans=max(books,ans);
            books=1;
        } printf("%d\n",ans);
}


#include<iostream>
using namespace std;
int main()
{
int n,m=0,t,l=0,a[100001]={0},ind=0;
cin>>n>>t;
for(int i=0;i<n;i++)
{
cin>>a[i];
m+=a[i];
while(m>t){m-=a[ind++];}
if(l<i-ind+1)l=i-ind+1;
}
cout<<l;
return 0;
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    bool fits=0;
    scanf("%d %d",&n,&t);
    FOR(i,0,n,1){
        scanf("%d",&x);
        if(ctr+x<=t){
            ctr+=x;
            fits=1;
            books++;
        }else{
            ctr=x;
            ans=max(ans,books);
            books=1;
        }
    }
    if(fits){
        (n==1)?printf("%d\n",1):printf("%d\n",ans);
    }else
    printf("%d\n",0);

}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        }
        if(n==1 && arr[0]<=t ){
            printf("%d",1);
        }else{
        FOR(i,0,n,1){
            ctr=arr[i];
            current=i+1;
            while(ctr+arr[current]<=t && current <n){
                ctr+=arr[current++];
                books++;
            }ans=max(books,ans);
            books=1;
        } printf("%d\n",ans);
        }
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
int main()
{
    int n,t,x,ctr(0);
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        if(t>=arr[i]){
            t-=arr[i];
            ctr++;
        }
    } printf("%d",ctr);
}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
int main(){
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    bool fits=0;
    scanf("%d %d",&n,&t);
    FOR(i,0,n,1){
        scanf("%d",&x);
        if(ctr+x<=t){
            ctr+=x;
            fits=1;
            books++;
        }else{
            ctr=x;
            ans=max(ans,books);
            books=1;
        }
    }
    if(fits){
        (n==1)?printf("%d\n",1):printf("%d\n",ans);
    }else
    printf("%d\n",0);

}


#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,ans(0),books(0),ctr(0),current(0);
    bool fits=0;
    scanf("%d %d",&n,&t);
    int arr[n];
       FOR(i,0,n,1){
        scanf("%d",&arr[i]);
        }
        FOR(i,0,n,1){
            ctr=arr[i];
            current=i+1;
            while(ctr+arr[current]<=t && current <n){
                ctr+=arr[current++];
                books++;
                fits=1;
                ans=max(books,ans);
            }
            books=1;
        }  if(fits){
        (n==1)?printf("%d\n",1):printf("%d\n",ans);
    }else
    printf("%d\n",0);
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int books, time, t, max = 0;
	cin >> books >> time;
	vector<int> timeofBooks = vector<int>(books);
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			if (time_readed > time)
			{
				break;
			}
			else
				++book_readed;;
		}
		if (book_readed > max)
			max = book_readed;
		if (max == books)
			break;
	}
	cout << max;
	system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, t, max = 0;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			if (time_readed > time)
			{
				if (book_readed > max)
					max = book_readed;
				break;
			}
			else
				++book_readed;;
		}
		if (book_readed > max)
			max = book_readed;
		if (max == books)
			break;
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int books, time, t, max = 0;
	int book_readed = 0, time_readed = 0, start = 0, j;
	cin >> books >> time;
	vector<int> timeofBooks = vector<int>(books);
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks[i] = t;
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		for (j=start; j < timeofBooks.size(); ++j)
		{

			if ((time_readed + timeofBooks[j]) > time)
			{
				break;
			}
			else
			{
				time_readed += timeofBooks[j];
				++book_readed;
			}

		}
		if (book_readed > max)
			max = book_readed;
		if (max == books)
			break;
		--book_readed;
		time_readed -= timeofBooks[i];
		start = j;
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, t, max = 0;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			++book_readed;
			if (time_readed > time)
			{
				if ((book_readed - 1) > max)
					max = book_readed - 1;

				break;

			}
			else if (j == timeofBooks.size() - 1 && book_readed > max)
			{
				max = book_readed;
				break;
			}
		}
		if (i==0 && j == timeofBooks.size() - 1)
		{
			max = books;
			break;
		}
	}
	cout << max;
	//system("pause");
}


//#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, t, max = 0;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			if (time_readed > time)
			{
				if (book_readed > max)
					max = book_readed;
				break;
			}
			else
				++book_readed;;
		}
		if (book_readed > max)
			max = book_readed;
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, time_readed = 0, t;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for(int i=0;i<books;++i)
		for (int j = i; j < books; ++j)
		{
			if (timeofBooks[j] < timeofBooks[i])
			{
				int temp = timeofBooks[j];
				timeofBooks[j] = timeofBooks[i];
				timeofBooks[i] = temp;
			}
		}
	for (int i = 0; i <= books; ++i)
	{
		time_readed += timeofBooks[i];
		if (time_readed > time)
		{
			cout << i;
			flag = true;
			break;
		}
	}
	if (!flag)
		cout << books;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int books, time, t, max = 0;
	cin >> books >> time;
	vector<int> timeofBooks = vector<int>(books);
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks[i] = t;
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			if (time_readed > time)
			{
				break;
			}
			else
				++book_readed;;
		}
		if (book_readed > max)
			max = book_readed;
		if (max == books)
			break;
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, time_readed = 0, t;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for(int i=0;i<books;++i)
		for (int j = i; j < books; ++j)
		{
			if (timeofBooks[j] < timeofBooks[i])
			{
				int temp = timeofBooks[j];
				timeofBooks[j] = timeofBooks[i];
				timeofBooks[i] = temp;
			}
		}
	for (int i = 0; i <= books; ++i)
	{
		time_readed += timeofBooks[i];
		if (time_readed > time)
		{
			cout << i;
			flag = true;
			break;
		}
	}
	if (!flag)
		cout << books;
	system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int books, time, t, max = 0;
	cin >> books >> time;
	vector<int> timeofBooks = vector<int>(books);
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			if (time_readed > time)
			{
				break;
			}
			else
				++book_readed;;
		}
		if (book_readed > max)
			max = book_readed;
		if (max == books)
			break;
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	bool flag = false;
	int books, time, time_readed = 0, t;
	cin >> books >> time;
	for (int i = 1; i <= books; ++i)
	{
		cin >> t;
		time_readed += t;
		if (time_readed > time)
		{
			flag = true;
			cout << i-1;
			break;
		}
	}
	if (!flag)
		cout << books;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, t, max = 0;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			if (time_readed > time)
			{
				if (book_readed > max)
					max = book_readed;
				break;
			}
			else
				++book_readed;;
		}
		if (book_readed > max)
			max = book_readed;
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, t, max = 0;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for (int i = 0; i < timeofBooks.size()-max; ++i)
	{
		int book_readed = 0, time_readed = 0, j;
		for (j = i; j < timeofBooks.size(); ++j)
		{
			time_readed += timeofBooks[j];
			++book_readed;
			if (time_readed > time)
			{
				if ((book_readed - 1) > max)
				{
					max = book_readed - 1;
					break;
				}
			}
			else if (j == timeofBooks.size() - 1 && book_readed > max)
			{
				max = book_readed;
				break;
			}
		}
		if (i==0 && j == timeofBooks.size() - 1)
		{
			max = books;
			break;
		}
	}
	cout << max;
	//system("pause");
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> timeofBooks;
	bool flag = false;
	int books, time, time_readed = 0, t;
	cin >> books >> time;
	for (int i = 0; i < books; ++i)
	{
		cin >> t;
		timeofBooks.push_back(t);
	}
	for(int i=0;i<books;++i)
		for (int j = i; j < books; ++j)
		{
			if (timeofBooks[j] < timeofBooks[i])
			{
				int temp = timeofBooks[j];
				timeofBooks[j] = timeofBooks[i];
				timeofBooks[i] = temp;
			}
		}
	for (int i = 0; i <= books; ++i)
	{
		time_readed += timeofBooks[i];
		if (time_readed > time)
		{
			cout << i;
			flag = true;
			break;
		}
	}
	if (!flag)
		cout << books;
	//system("pause");
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <cmath>
#include <list>
#define N 10000000
using namespace std;
long long int inp[N],n,x,y,sum,t;
int main()
{
    // ==========================================
//  freopen ("inp.cpp", "r", stdin);
//  freopen ("out.cpp", "w", stdout);
    // ==========================================
    int i;
    cin>>n>>t;
    for(i=1; i<=n; i++) cin>>inp[i];
    x=y=1;
    sum=0;
    long long mx=0;
    for(i=1; i<=n; i++)
    {
        sum+=inp[i];
        while(sum>=t) sum-=inp[x++];
        y++;
    }
    //cout<<"sum = "<<sum<<endl;
    cout<<y-x<<endl;
    return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

int main()
{
    //INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]=a[i-1]+a[i];
    }
    int res=0;
    For(i,1,n)
    {
        int lo=i, hi=n, pos=-1;
        while(lo<=hi)
        {
            int mid=(lo+hi)/2;
            if((a[mid]-a[i-1] <=t))
            {
                pos=mid;
                lo=mid+1;
            }
            else hi=mid-1;
        }
        if(pos>0) res=max(res,pos-i+1);
    }
    cout<<res<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

int main()
{
    //INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    //int ans;
    int x=0,y=1;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]=a[i-1]+a[i];
        if(a[i]-a[x]<=t) y++;
        else x++;
        //debug(y-x);
    }

    cout<<y-x<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];
queue<int>q;

int main()
{
    //INPUT("279B");
    cin>>n>>t;
    int ans=0,sum=0;
    For(i,1,n)
    {
        cin>>a[i];
        q.push(a[i]);
        sum+=a[i];
        a[i]=a[i-1]+a[i];
        if(sum > t)
        {
            sum-=q.front();
            q.pop();
        }
        ans=max(ans,q.size());
    }
    cout<<ans<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

/*int main()
{
    INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    int res=0;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]=a[i-1]+a[i];
    }
    For(i,1,n)
    {
        int lo=i, hi=n, pos=-1;
        while(lo<=hi)
        {
            int mid=(lo+hi)/2;
            if((a[mid]-a[i-1] <=t))
            {
                pos=mid;
                lo=mid+1;
            }
            else hi=mid-1;
        }
        if(pos>0) res=max(res,pos-i+1);
    }
    cout<<res<<endl;
return 0;
}*/
int main()
{
    //INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    int res=0;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]=a[i-1]+a[i];
        int lo=1,hi=i,pos=-1;
        while(lo<=hi)
        {
            int mid=(lo+hi)/2;
            if(a[i]-a[mid-1] <=t)
            {
                hi=mid-1;
                pos=mid;
            }
            else lo=mid+1;
        }
        if(pos>0) res=max(res,i-pos+1);
    }
    cout<<res<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

/*int main()
{
    //INPUT("279B");
    cin>>n>>t;
    int ans=0,sum=0;
    int x=0,y=0;
    int b,cnt=0;
    For(i,1,n)
    {
        cin>>b;
        cnt++;
        sum+=b;
        a[y++]=b;
        if(sum > t)
        {
            sum-=a[x++];
            cnt--;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
return 0;
}*/

int main()
{
   // INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]+=a[i-1];
    }
    int x=0,y=1,ans=0;
    For(i,1,n)
    {
        while(y<=n)
        if(a[y]-a[x] <=t){ans=max(ans,y-x);y++;}
        else {x++;break;}
       // debug(ans);
    }
    cout<<ans<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t;
queue<int>q;

int main()
{
    //INPUT("279B");
    cin>>n>>t;
    int ans=0,sum=0,a;
    For(i,1,n)
    {
        cin>>a;
        q.push(a);
        sum+=a;
        if(sum > t)
        {
            sum-=q.front();
            q.pop();
        }
        ans=max(ans,q.size());
    }
    cout<<ans<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5],sum[100000+5];

int main()
{
    //INPUT("279B");
    cin>>n>>t;
    sum[0]=0;
    For(i,1,n)
    {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    int res=0;
    For(i,1,n)
    {
        int lo=i, hi=n, pos=-1;
        while(lo<=hi)
        {
            int mid=(lo+hi)/2;
            if((sum[mid]-sum[i-1] <=t))
            {
                pos=mid;
                lo=mid+1;
            }
            else hi=mid-1;
        }
        if(pos>0) res=max(res,pos-i+1);
       // debug(res);
    }
    cout<<res<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

/*int main()
{
    //INPUT("279B");
    cin>>n>>t;
    int ans=0,sum=0;
    int x=0,y=0;
    int b,cnt=0;
    For(i,1,n)
    {
        cin>>b;
        cnt++;
        sum+=b;
        a[y++]=b;
        if(sum > t)
        {
            sum-=a[x++];
            cnt--;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
return 0;
}*/

int main()
{
   // INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    int x=0,y=1,ans=0;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]+=a[i-1];
        while(y<=i)
        {
            if(a[y]-a[x] <=t){ans=max(ans,y-x);y++;}
            else {x++;break;}
        }
    }
    cout<<ans<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

int main()
{
   // INPUT("279B");
    cin>>n>>t;
    a[0]=0;
    int res=0;
    int x=0,y=1;
    For(i,1,n)
    {
        cin>>a[i];
        a[i]=a[i-1]+a[i];
        if(a[i]-a[x]<=t) y++;
        else x++;
        res=max(res,y-x);
       // debug(res);
    }

    cout<<res<<endl;
return 0;
}


//===========================================
// Author: Nguyen Quoc Nhan
// Problem name:
// Time limit:
// Run Time:
//===========================================

#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define For(i,a,b) for(int i=a; i<=b; i++)
#define INPUT(file) freopen(file".inp","r",stdin);
#define OUTPUT(file) freopen(file".out","w",stdout);
#define INF 111111111
#define MaxInt 2147483647
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug(a) cout<< #a << " = " <<a<<endl;
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

int n,t,a[100000+5];

int main()
{
    //INPUT("279B");
    cin>>n>>t;
    int ans=0,sum=0;
    int x=0,y=0;
    int b,cnt=0;
    For(i,1,n)
    {
        cin>>b;
        cnt++;
        sum+=b;
        a[y++]=b;
        if(sum > t)
        {
            sum-=a[x++];
            cnt--;
        }
        //else y++;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
        scanf("%I64d", &arr[i]);
    for(long long i=0; i<n-maxi; i++)
    {
        sum=arr[i];
        cant=0;
        x=i;
        while(sum<=t and x<n)
        {
            cant++;
            if(cant>maxi)
                maxi=cant;
            sum+=arr[x];
            x++;
        }
    }
    printf("%I64d", maxi);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
        if(arr[i]<=t)
            b1=false;
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    long long x=0, cant=0, may=0;
    sum=0;
    for(int i=0; i<n; i++)
    {
        while(sum<t and x<n)
        {
            sum+=arr[x];
            cant++;
            x++;
            if(sum>t)
            {
                cant--;
                sum-=arr[i];
                break;
            }
            if(cant>may)
                may=cant;
        }
    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x;
bool b1=true;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
        if(arr[i]<=t)
            b1=false;
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    else if(b1==true)
    {
        printf("0");
        return 0;
    }
    for(long long i=0; i<n-maxi; i++)
    {
        sum=0;
        cant=0;
        x=i;
        while(sum<=t and x<n)
        {
            sum+=arr[x];
            if(sum<=t)
            cant++;
            if(cant>maxi)
                maxi=cant;
            x++;
        }
    }
    printf("%I64d", maxi);
    return 0;
}


#include <stdio.h>
long long  t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
int n;
bool b1=true;
int main()
{
    scanf("%d%I64d", &n, &t);
    for(int i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        if(arr[i]<=t)
            b1=false;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    long long x=0, cant=0, may=1;
    sum=0;
    for(int i=0; i<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        sum+=arr[i];
        cant++;
        while(sum<t and x<n)
        {

                x++;
                sum+=arr[x];
                cant++;
                if(sum>t)
                {
                    cant--;
                    sum-=arr[i];
                    break;
                }
                if(cant>may)
                    may=cant;
        }

    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long  t, arr[100005], cant=0, sum=0, may=1;
int n, x;
bool b1=true;
int main()
{
    scanf("%d%I64d", &n, &t);
    for(int i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        if(arr[i]<=t)
            b1=false;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    sum=0;
    int y=0;
    while(x<n)
    {
        //printf("%d ", sum);
        sum+=arr[x];
        x++;
        if(sum>t)
        {
            sum-=arr[y];
            y++;
         }
         if((x-y)>may)
            may=(x-y);
     }
    printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
        if(arr[i]<=t)
            b1=false;
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    long long x=0, cant=0, may=0;
    sum=0;
    for(int i=0; i<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        if(arr[i]<=t)
        {
            while(sum<t and x<n)
            {
                sum+=arr[x];
                cant++;
                x++;
                if(sum>t)
                {
                    cant--;
                    sum-=arr[i];
                    //printf("%d\n", arr[i]);
                    break;
                }
                if(cant>may)
                    may=cant;
            }
        }
        else
        {
            sum=0;
            cant=0;
        }

    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
        scanf("%I64d", &arr[i]);
    for(long long i=0; i<n-maxi; i++)
    {
        sum=0;
        cant=0;
        x=i;
        while(sum<=t and x<n)
        {
            sum+=arr[x];
            if(sum<=t)
            cant++;
            if(cant>maxi)
                maxi=cant;
            x++;
        }
    }
    printf("%I64d", maxi);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
bool busqueda(long long N)
{
    for(long long i=0; i<=n-N; i++)
    {
        sum=0;
        cant=0;
        x=i;
        y=x+N;
        while(sum<=t and x<y)
        {
            //if(N==3)
            //printf("%I64d ", arr[x]);
            sum+=arr[x];
            if(sum<=t)
            cant++;
            else
                break;
            if(cant>=N and sum<=t)
                return true;
            x++;
        }
    }
    return false;
}
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    piv=0;
    piv2=n;
    while((piv+1)<piv2)
    {

        med=(piv+piv2)/2;
        //printf("%d", med);
        if(busqueda(med)==true)
            piv=med;
        else
            piv2=med-1;
    }
    if(busqueda(piv2)==true)
        printf("%I64d", piv2);
    else
        printf("%I64d", piv);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
bool busqueda(long long N)
{
    for(long long i=0; i<=n-N; i++)
    {
        sum=0;
        cant=0;
        x=i;
        y=x+N;
        while(sum<=t and x<y)
        {
            //if(N==3)
            //printf("%I64d ", arr[x]);
            sum+=arr[x];
            if(sum<=t)
            cant++;
            if(cant>=N and sum<=t)
                return true;
            x++;
        }
    }
    return false;
}
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    piv=0;
    piv2=n;
    while((piv+1)<piv2)
    {

        med=(piv+piv2)/2;
        //printf("%d", med);
        if(busqueda(med)==true)
            piv=med;
        else
            piv2=med-1;
    }
    if(busqueda(piv2)==true)
        printf("%I64d", piv2);
    else
        printf("%I64d", piv);
    return 0;
}


#include <stdio.h>
long long  t, arr[100005], cant=0, sum=0, may=1;
int n, x;
bool b1=true;
int main()
{
    scanf("%d%I64d", &n, &t);
    for(int i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        if(arr[i]<=t)
            b1=false;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    sum=0;
    for(int i=0; i<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        if(sum<t)
        {
            while(sum<t and x<n)
            {
                    sum+=arr[x];
                    cant++;
                    x++;
                    if(sum>t)
                    {
                        //printf("sali%I64d %d ", sum, x);
                        cant--;
                        sum-=arr[i];
                        break;
                    }
                    if(cant>may)
                        may=cant;
            }

        }
        else
        {
            cant--;
            sum-=arr[i];
            if(sum<0)
                sum=0;
        }

    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
        if(arr[i]<=t)
            b1=false;
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    long long x=0, cant=0, may=0;
    sum=0;
    for(int i=0; i<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        if(arr[i]<t)
        {
            while(sum<t and x<n)
            {
                sum+=arr[x];
                cant++;
                x++;
                if(sum>t)
                {
                    cant--;
                    sum-=arr[i];
                    //printf("%d\n", arr[i]);
                    break;
                }
                if(cant>may)
                    may=cant;
            }
        }
        else
        {
            sum=0;
            cant=0;
        }

    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
bool busqueda(long long N)
{
    for(long long i=0; i<=n-N; i++)
    {
        sum=0;
        cant=0;
        x=i;
        y=x+N;
        while(sum<=t and x<y)
        {
            //if(N==3)
            //printf("%I64d ", arr[x]);
            sum+=arr[x];
            if(sum<=t)
            cant++;
            else
                break;
            if(cant>=N and sum<=t)
                return true;
            x++;
        }
    }
    return false;
}
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
        if(arr[i]<=t)
            b1=false;
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    piv=0;
    piv2=n;
    while((piv+1)<piv2)
    {

        med=(piv+piv2)/2;
        //printf("%d", med);
        if(busqueda(med)==true)
            piv=med;
        else
            piv2=med-1;
    }
    if(busqueda(piv2)==true)
        printf("%I64d", piv2);
    else
        printf("%I64d", piv);
    return 0;
}


#include <stdio.h>
long long  t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
int n;
bool b1=true;
int main()
{
    scanf("%d%I64d", &n, &t);
    for(int i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        if(arr[i]<=t)
            b1=false;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    long long x=0, cant=0, may=1;
    sum=0;
    for(int i=0; i<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        while(sum<t and x<n)
        {
                sum+=arr[x];
                cant++;
                x++;
                if(sum>t)
                {
                    //printf("sali%d %d ", sum, x);
                    cant--;
                    sum-=arr[i];
                    break;
                }
                if(cant>may)
                    may=cant;
        }

    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
bool b1=true;
bool busqueda(long long N)
{
    for(long long i=0; i<=n-N; i++)
    {
        sum=0;
        cant=0;
        x=i;
        y=x+N;
        while(sum<=t and x<y)
        {
            //if(N==3)
            //printf("%I64d ", arr[x]);
            sum+=arr[x];
            if(sum<=t)
            cant++;
            else
                break;
            if(cant>=N and sum<=t)
                return true;
            x++;
        }
    }
    return false;
}
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
        if(arr[i]<=t)
            b1=false;
    }
    if(sum<=t)
    {
        printf("%I64d", n);
        return 0;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    piv=0;
    piv2=n;
    while((piv+1)<piv2)
    {

        med=(piv+piv2)/2;
        //printf("%d", med);
        if(busqueda(med)==true)
        {
            piv=med;
            if(med>maxi)
                maxi=med;
        }
        else
            piv2=med-1;
    }
    printf("%I64d", med);
    return 0;
}