#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-15);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<long double, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<long double, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(long double lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    long double st = -1e18, en = 1e18;
    while(isGreater(en, st) == 1)
    {
        long double mid = (st + en)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid;
    }
    pair<ll, int> temp = get(st + eps);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include <stdio.h>
#include <vector>
#include <cstring>
using namespace std;
int main() {
    int n,k,A[300000];
    scanf("%i%i",&n,&k);
    vector<int> D1(n),D2(n);
    for(int i=0;i<n;i++) scanf("%i",A+i), D1[i]=A[i]-A[0];

    for(int locK=2;locK<=k;locK++){
        D2[locK-1]=D1[locK-2];
        for(int i=locK;i<n-k+locK;i++){
            D2[i]=D2[i-1]+A[i]-A[i-1];
            if(D2[i]>D1[i-1]) D2[i]=D1[i-1];
        }
        D1=D2;
        memset(&D2[0],0,D2.size());
    }
    printf("%i",D1[n-1]);
}


#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n,k,A[300000];
    scanf("%i%i",&n,&k);
    for(int i=0;i<n;i++) scanf("%i",A+i);
    int sum=A[n-1]-A[0];
    for(int i=n-1;i>0;i--) A[i]-=A[i-1];
    sort(A+1,A+n);

    for(int i=n-1;i>=n-k+1;i--) sum-=A[i];
    printf("%i",sum);
}


#include <stdio.h>
#include <vector>
using namespace std;
int main() {
    int n,k,A[300000];
    scanf("%i%i",&n,&k);
    vector<int> D1(n),D2(n);
    for(int i=0;i<n;i++) scanf("%i",A+i), D1[i]=A[i]-A[0];

    bool b=true;
    for(int locK=2;locK<=k;locK++){
        if(b){
            D2[locK-1]=D1[locK-2];
            for(int i=locK;i<n-k+locK;i++){
                D2[i]=D2[i-1]+A[i]-A[i-1];
                if(D2[i]>D1[i-1]) D2[i]=D1[i-1];
            }
        }
        else{
            D1[locK-1]=D2[locK-2];
            for(int i=locK;i<n-k+locK;i++){
                D1[i]=D1[i-1]+A[i]-A[i-1];
                if(D1[i]>D2[i-1]) D1[i]=D2[i-1];
            }
        }
        b=!b;
    }
    if(b) printf("%i",D1[n-1]);
    else printf("%i",D2[n-1]);
}


#include <stdio.h>
#include <vector>
#include <cstring>
using namespace std;
int main() {
    int n,k,A[300000];
    scanf("%i%i",&n,&k);
    vector<int> D1(n),D2(n);
    for(int i=0;i<n;i++) scanf("%i",A+i), D1[i]=A[i]-A[0];

    for(int locK=2;locK<=k;locK++){
        for(int i=locK-1;i<n-k+locK;i++){
            for(int j=locK-2;j<i;j++){
                if(!D2[i] || D2[i]<D1[j]+i-j-1) D2[i]=D1[j]+i-j-1;
            }
        }
        D1=D2;
        memset(&D2[0],0,D2.size());
    }
    printf("%i",D1[n-1]);
}


#include <stdio.h>
#include <vector>
#include <cstring>
using namespace std;
int main() {
    int n,k,A[300000];
    scanf("%i%i",&n,&k);
    vector<int> D1(n),D2(n);
    for(int i=0;i<n;i++) scanf("%i",A+i), D1[i]=A[i]-A[0];

    for(int locK=2;locK<=k;locK++){
        D2[locK-1]=D1[locK-2];
        for(int i=locK;i<n-k+locK;i++){
            D2[i]=D2[i-1]+A[i]-A[i-1];
            if(D2[i]>D1[i-1]) D2[i]=D1[i-1];
        }
        D1=D2;
    }
    printf("%i",D1[n-1]);
}


#include <stdio.h>
#include <vector>
using namespace std;
int main() {
    int n,k,A[300000];
    scanf("%i%i",&n,&k);
    vector<int> D1(n),D2(n);
    for(int i=0;i<n;i++) scanf("%i",A+i), D1[i]=A[i]-A[0];

    bool b=true;
    for(int locK=2;locK<=k;locK++){
        //if(b) printf("%i\n",D1[n-k+locK-2]);
        //else printf("%i\n",D2[n-k+locK-2]);
        if(b){
            D2[locK-1]=D1[locK-2];
            D2[n-k+locK-1]=D1[locK-2]+A[n-k+locK-1]-A[locK-1];
            if(D2[n-k+locK-1]>D1[n-k+locK-2]) D2[n-k+locK-1]=D1[n-k+locK-2];
        }
        else{
            D1[locK-1]=D2[locK-2];
            D1[n-k+locK-1]=D2[locK-2]+A[n-k+locK-1]-A[locK-1];
            if(D1[n-k+locK-1]>D2[n-k+locK-2]) D1[n-k+locK-1]=D2[n-k+locK-2];
        }
        b=!b;
    }
    if(b) printf("%i",D1[n-1]);
    else printf("%i",D2[n-1]);
}


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

using namespace std;

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m], indx[m];
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
      indx[x-1] = x;
    }
    prev = a[x];
  }

  int i, j, max_idx;

    for (i = 0; i < k-1; i++)
    {
        max_idx = i;
        for (j = i+1; j < m; j++)
        if (diff[j] > diff[max_idx])
            max_idx = j;

        swap(&diff[max_idx], &diff[i]);
        swap(&indx[max_idx], &indx[i]);
    }

    sort(indx, indx + k-1);

    int start = 0, sum = 0;
    for(int j = 0; j < k-1; j ++){
      sum += (a[indx[j] - 1] - a[start]);
      start = indx[j];
    }
    if(k = 1){
      cout<<a[n-1] - a[0]<<endl;
    }
    else
      cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m], sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
    }
    prev = a[x];
  }

  sort(diff, diff + m - k + 1);

  for(int x = 0; x < m - k + 1; x ++){
    sum += diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m];
  long long sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
      sum += diff[x-1];
    }
    prev = a[x];
  }

  int low = -1, tmp, pvt = m - k + 1;
  for(int j = 0; j < n; j ++){
    if(diff[j] < diff[pvt]){
      low++;
      tmp = diff[low];
      diff[low] = diff[j];
      diff[j] = tmp;
    }
  }

  //sort(diff, diff + (m - k + 1));

  for(int x = m-1; x > m - k; x --){
    sum -= diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m], sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
      sum += diff[x-1];
    }
    prev = a[x];
  }

  int max_idx;

  for (int i = 0; i < k-1; i++)
  {
      max_idx = i;
      for (int j = i+1; j < m; j++)
      if (diff[j] > diff[max_idx])
          max_idx = j;

      swap(&diff[max_idx], &diff[i]);
  }

  for(int x = 0; x < k - 1; x ++){
    sum -= diff[x];
  }

  if(k == 1){
    cout<<a[n-1] - a[0]<<endl;
  }
  else
    cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m];
  long long sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
      sum += diff[x-1];
    }
    prev = a[x];
  }

  int low = -1, tmp, pivot = m - k + 1;
  for(int j = 0; j < m; j ++){
    if(diff[j] < diff[pivot]){
      low++;
      tmp = diff[low];
      diff[low] = diff[j];
      diff[j] = tmp;
    }
  }

  //sort(diff, diff + (m - k + 1));

  for(int x = m-1; x > m - k; x --){
    sum -= diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m];
  long long sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
    }
    prev = a[x];
  }

  int low = -1, tmp, pivot = m - k + 1;
  for(int j = 0; j < m; j ++){
    if(diff[j] < diff[pivot]){
      low++;
      tmp = diff[low];
      diff[low] = diff[j];
      diff[j] = tmp;
    }
  }

  //sort(diff, diff + (m - k + 1));

  for(int x = 0; x < m - k + 1; x ++){
    sum += diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m], sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
    }
    prev = a[x];
  }

  int low = -1, tmp, pivot = m - k + 1;
  for(int j = 0; j < n; j ++){
    if(diff[j] < diff[pivot]){
      low++;
      tmp = diff[low];
      diff[low] = diff[j];
      diff[j] = tmp;
    }
  }

  //sort(diff, diff + (m - k + 1));

  for(int x = 0; x < m - k + 1; x ++){
    sum += diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m], indx[m];
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
      indx[x-1] = x;
    }
    prev = a[x];
  }

  int i, j, max_idx;

    for (i = 0; i < k-1; i++)
    {
        max_idx = i;
        for (j = i+1; j < m; j++)
        if (diff[j] > diff[max_idx])
            max_idx = j;

        swap(&diff[max_idx], &diff[i]);
        swap(&indx[max_idx], &indx[i]);
    }

    sort(indx, indx + k-1);

    int start = 0, sum = 0;
    for(int j = 0; j < k-1; j ++){
      sum += (a[indx[j] - 1] - a[start]);
      start = indx[j];
    }
    if(k == 1){
      cout<<a[n-1] - a[0]<<endl;
    }
    else
      cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m], sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
    }
    prev = a[x];
  }

  for(int g = 0; g < m; g ++)
    cout<<diff[g]<<" ";
  cout<<endl;

  int low = -1, tmp, pivot = m - k + 1;
  for(int j = 0; j < n; j ++){
    if(diff[j] < pivot){
      low++;
      tmp = diff[low];
      diff[low] = diff[j];
      diff[j] = tmp;
    }
  }

  for(int g = 0; g < m; g ++)
    cout<<diff[g]<<" ";
  cout<<endl;

  //sort(diff, diff + (m - k + 1));

  for(int x = 0; x < m - k + 1; x ++){
    sum += diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

int main(){

  #ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif

  int n, k;
  cin>>n>>k;
  int m = n - 1;
  int a[n], prev, diff[m];
  long long sum = 0;
  for(int x = 0; x < n; x ++){
    cin>>a[x];
    if(x != 0){
      diff[x-1] = a[x] - prev;
    }
    prev = a[x];
  }

  sort(diff, diff + m);

  for(int x = 0; x < m - k + 1; x ++){
    sum += diff[x];
  }

  cout<<sum<<endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{

    ll n,i,j,k,l,x;

    cin>>n>>k;

    ll a[n];

    for(i=0;i<n;i++)
        cin>>a[i];

    vector<ll> v;

    for(i=1;i<n;i++)
    {
        v.pb(a[i]-a[i-1]);
    }

    sort(v.begin(),v.end());

    ll sum=0;

    for(i=0;i<k;i++)
    {
        sum+=v[i];
    }
    cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{

    ll n,i,j,k,l,x;

    cin>>n>>k;

    ll a[n];

    for(i=0;i<n;i++)
        cin>>a[i];

    vector<ll> v;

    for(i=1;i<n;i++)
    {
        v.pb(a[i]-a[i-1]);
    }

    sort(v.begin(),v.end());

    ll sum=0;

    for(i=0;i<min(k,(ll)v.size());i++)
    {
        sum+=v[i];
    }
    cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{

    ll n,i,j,k,l,x;

    cin>>n>>k;

    ll a[n];

    for(i=0;i<n;i++)
        cin>>a[i];

    vector<ll> v;

    for(i=1;i<n;i++)
    {
        v.pb(a[i]-a[i-1]);
    }

    sort(v.begin(),v.end());

    ll sum=0;

    for(i=0;i<min(k,v.size());i++)
    {
        sum+=v[i];
    }
    cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{

    ll n,i,j,k,l,x;

    cin>>n>>k;

    ll a[n];

    for(i=0;i<n;i++)
        cin>>a[i];

    vector<ll> v;

    for(i=1;i<n;i++)
    {
        v.pb(v[i]-v[i-1]);
    }

    sort(v.begin(),v.end());

    ll sum=0;

    for(i=0;i<k;i++)
    {
        sum+=v[i];
    }
    cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{

    ll n,i,j,k,l,x;

    cin>>n>>k;

    vector<ll> v;

    cin>>x;
    v.pb(x);

    ll p=x;

    for(i=1;i<n;i++)
    {
        cin>>x;
        if(x==p)
            continue;

        v.pb(x);
        p=x;
    }

    ll sz=v.size();

    ll pp=sz-k;

    if(pp<=0)
    {
        cout<<"0";
        return 0;
    }
    ll mn=100000000000000;

    for(i=pp;i<sz;i++)
    {
        //cout<<v[i]-v[i-pp]<<endl;
        mn=min(mn,v[i]-v[i-pp]);
    }

    cout<<mn;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{

    ll n,i,j,k,l,x;

    cin>>n>>k;

    ll a[n];

    for(i=0;i<n;i++)
        cin>>a[i];

    vector<ll> v;

    for(i=1;i<n;i++)
    {
        v.pb(a[i]-a[i-1]);
    }

    sort(v.begin(),v.end());

    ll sum=0;

    for(i=0;i<n-k;i++)
    {
        sum+=v[i];
    }
    cout<<sum;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
long long arr[maxd],n,m;
bool check(long long x)
{
    long long last = arr[1],k = m-1;
    for(int i=2;i<=n;i++)
    {
        if(arr[i] - last > x)
        {
            if(!k) return false;
            k--;

            x -= arr[i-1] - last;
            //printf("%d %lld %lld %lld\n",i,arr[i-1],last,x);
            last = arr[i];
        }
    }
     //printf("%lld %lld %lld\n",arr[n],last,x);

    return true;
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)  cin >> arr[i];
    long long l = 0ll, r = 1e10, ans;
    while(l<=r)
    {
        long long mid = (long long)(l+r)/2;
        if(check(mid)) ans = mid,r = mid-1;
        else l = mid+1;
    }

    printf("%lld",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
long long arr[maxd],n,m,suff[maxd],sum;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)  cin >> arr[i];
    for(int i=2;i<=n;i++)
    {
        suff[i-1] = arr[i] - arr[i-1];
        sum += suff[i-1];
    }
    sort(arr+1,arr+n);
    for(int i=n-m+1;i<=n;i++)
        sum -= suff[i];

    printf("%lld",sum);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
long long arr[maxd],n,m;
bool check(long long x)
{
    long long last = arr[1],k = m-1;
    for(int i=2;i<=n;i++)
    {
        if(arr[i] - last > x)
        {
            if(!k) return false;
            k--;

            x -= arr[i-1] - last;
            //printf("%d %d %d\n",arr[i-1],last,x);
            last = arr[i];
        }
    }
    // printf("%d %d %d\n",arr[n],last,x);
    return true;
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)  scanf("%lld",&arr[i]);
    long long l = 0, r = 1e10,ans;
    while(l<=r)
    {
        long long mid = (l+r)/2;
        if(check(mid)) ans = mid,r = mid-1;
        else l = mid+1;
    }
    printf("%lld",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
long long arr[maxd],n,m,suff[maxd],sum;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)  cin >> arr[i];
    for(int i=1;i<n;i++)
    {
        suff[i] = arr[i+1] - arr[i];
    }
    sort(arr+1,arr+n);
    for(int i=1;i<=n-m;i++)
        sum += suff[i];

    printf("%lld",sum);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
long long arr[maxd],n,m,suff[maxd],sum;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)  cin >> arr[i];
    for(int i=2;i<=n;i++)
    {
        suff[i-1] = arr[i] - arr[i-1];
        sum += suff[i-1];
    }
    sort(suff+1,suff+n);
    for(int i=n-m+1;i<=n;i++)
        sum -= suff[i];

    printf("%lld",sum);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
int arr[maxd],n,m;
bool check(int x)
{
    int last = arr[1],k = m-1;
    for(int i=2;i<=n;i++)
    {
        if(arr[i] - last > x)
        {
            if(!k) return false;
            k--;

            x -= arr[i-1] - last;
            //printf("%d %d %d\n",arr[i-1],last,x);
            last = arr[i];
        }
    }
    return true;
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)  scanf("%d",&arr[i]);
    int l = 0, r = 1e9,ans;
    while(l<=r)
    {
        int mid = (l+r)/2;
        if(check(mid)) ans = mid,r = mid-1;
        else l = mid+1;
    }
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 2e5+10;
int arr[maxd],n,m;
bool check(int x)
{
    int last = arr[1],k = m-1;
    for(int i=2;i<=n;i++)
    {
        if(arr[i] - last > x)
        {
            if(!k) return false;
            k--;

            x -= arr[i-1] - last;
            last = arr[i];
            //printf("%d %d\n",arr[i],x);
        }
    }
    return true;
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)  scanf("%d",&arr[i]);
    int l = 0, r = 1e9,ans;
    //check(8);
    while(l<=r)
    {
        int mid = (l+r)/2;
        if(check(mid)) ans = mid,r = mid-1;
        else l = mid+1;
    }
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxd = 3e5+10;
long long arr[maxd],n,m,suff[maxd],sum;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)  cin >> arr[i];
    for(int i=1;i<n;i++)
    {
        suff[i] = arr[i+1] - arr[i];
        sum += suff[i];
    }
    sort(arr+1,arr+n);
    for(int i=n-m+1;i<=n;i++)
        sum -= suff[i];

    printf("%lld",sum);
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=3e5+10;
long long a[MAXN];
long long  cf[MAXN];
bool cmp(int a,int b)
{
	return a<=b;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i>=2) cf[i-1]=a[i]-a[i-1];
	}
	long long sum=0;
//	if(k<=n/2)
//	{
		sort(cf+1,cf+n,cmp);
		for(int i=1;i<=n-k;i++)
		sum+=cf[i];
		printf("%d\n",sum);
//	}

}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=3*1e5+5;
long long a[MAXN];
long long  cf[MAXN];
bool cmp(int a,int b)
{
	return a<=b;
}
int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>=2) cf[i-1]=a[i]-a[i-1];
	}
	long long sum=0;
		sort(cf+1,cf+n,cmp);
//		for(int i=0;i<=n;i++)
//		cout<<cf[i]<<' ';
//		cout<<endl;
		for(int i=1;i<=n-k;i++)
		sum+=cf[i];
		printf("%lld\n",sum);

}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=3*1e5+5;
long long a[MAXN];
long long  cf[MAXN];
bool cmp(int a,int b)
{
	return a<=b;
}
int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>=2) cf[i-1]=a[i]-a[i-1];
	}
	long long sum=0;
		sort(cf+1,cf+n,cmp);
//		for(int i=0;i<=n;i++)
//		cout<<cf[i]<<' ';
//		cout<<endl;
		for(int i=1;i<=n-k;i++)
		sum+=cf[i];
		printf("%lld\n",sum);

}
close


#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=3*1e5+5;
long long a[MAXN];
long long  cf[MAXN];
bool cmp(int a,int b)
{
	return a<b;
}
int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>=2) cf[i-1]=a[i]-a[i-1];
	}
	long long sum=0;
		sort(cf+1,cf+n,cmp);
//		for(int i=0;i<=n;i++)
//		cout<<cf[i]<<' ';
//		cout<<endl;
		for(int i=1;i<=n-k;i++)
		sum+=cf[i];
		printf("%lld\n",sum);

}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=3e5+10;
int a[MAXN];
int cf[MAXN];
bool cmp(int a,int b)
{
	return a<=b;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i>=2) cf[i-1]=a[i]-a[i-1];
	}
	long long sum=0;
//	if(k<=n/2)
//	{
		sort(cf+1,cf+n,cmp);
		for(int i=1;i<=n-k;i++)
		sum+=cf[i];
		printf("%d\n",sum);
//	}

}


#include<iostream>
#include<climits>
using namespace std;

int minCost(int* arr, int N, int K){
    int dp[2][N];
    for(int j=0; j<N; j++)
        dp[0][j]=arr[j]-arr[0];
    for(int i=1; i<K; i++){
        dp[i%2][i]=0;
        for(int j=i+1; j<N; j++){
            dp[i%2][j]=INT_MAX;
            for(int k=i-1; k<j; k++)
                dp[i%2][j]=min(dp[i%2][j], dp[(i-1)%2][k]+arr[j]-arr[k+1]);
        }
    }
    return dp[(K+1)%2][N-1];
}

int main(){
    int N, K;
    cin>>N>>K;
    int arr[N];
    for(int i=0; i<N; i++)
        cin>>arr[i];
    cout<<minCost(arr, N, K)<<endl;
    return 0;
}


#include<iostream>
#include<climits>
using namespace std;

int minCost(int* arr, int N, int K){
    int dp[2][N];
    for(int j=0; j<N; j++)
        dp[0][j]=arr[j]-arr[0];
    for(int i=1; i<K; i++){
        dp[1][i]=0;
        for(int j=i+1; j<N; j++){
            dp[1][j]=INT_MAX;
            for(int k=i-1; k<j; k++)
                dp[1][j]=min(dp[1][j], dp[0][k]+arr[j]-arr[k+1]);
        }
        for(int j=i; j<N; j++)
            dp[0][j]=dp[1][j];
    }
    return dp[0][N-1];
}

int main(){
    int N, K;
    cin>>N>>K;
    int arr[N];
    for(int i=0; i<N; i++)
        cin>>arr[i];
    cout<<minCost(arr, N, K)<<endl;
    return 0;
}


#include<iostream>
#include<climits>
using namespace std;

long int minCost(int* arr, int N, int K){
    long int dp[K][N];
    for(int j=0; j<N; j++)
        dp[0][j]=arr[j]-arr[0];
    for(int i=1; i<K; i++){
        dp[i][i]=0;
        for(int j=i+1; j<N; j++){
            dp[i][j]=INT_MAX;
            for(int k=i-1; k<j; k++)
                dp[i][j]=min(dp[i][j], dp[i-1][k]+arr[j]-arr[k+1]);
        }
    }
    return dp[K-1][N-1];
}

int main(){
    int N, K;
    cin>>N>>K;
    int arr[N];
    for(int i=0; i<N; i++)
        cin>>arr[i];
    cout<<minCost(arr, N, K)<<endl;
    return 0;
}


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

int minCost(int* arr, int N, int K){
    int diff[N-1];
    for(int i=0; i<N-1; i++)
        diff[i]=arr[i]-arr[i+1];
    sort(diff, diff+N-1);
    int res=arr[N-1]-arr[0];
    for(int i=0; i<K-1; i++)
        res+=diff[i];
    return res;
}

int main(){
    int N, K;
    cin>>N>>K;
    int arr[N];
    for(int i=0; i<N; i++)
        cin>>arr[i];
    cout<<minCost(arr, N, K)<<endl;
    return 0;
}


#include<iostream>
#include<climits>
using namespace std;

int minCost(int* arr, int N, int K){
    int dp[K][N];
    for(int j=0; j<N; j++)
        dp[0][j]=arr[j]-arr[0];
    for(int i=1; i<K; i++){
        dp[i][i]=0;
        for(int j=i+1; j<N; j++){
            dp[i][j]=INT_MAX;
            for(int k=i-1; k<j; k++)
                dp[i][j]=min(dp[i][j], dp[i-1][k]+arr[j]-arr[k+1]);
        }
    }
    return dp[K-1][N-1];
}

int main(){
    int N, K;
    cin>>N>>K;
    int arr[N];
    for(int i=0; i<N; i++)
        cin>>arr[i];
    cout<<minCost(arr, N, K)<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p=hell){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;ll temp=x+y;temp%=hell;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(ll i=2;i<=15000000;i++)
        if(!prime[i])
        {
            for(ll j=i;j<=15000000;j+=i)
                if(!prime[j])
                    prime[j] = i;
        }
}*/
int main(){
	ios
	ll t = 1,tc = 0;
	//cin >> t;
	//sieve();
	while(t--){
		ll n,k;
		cin >> n >> k;
		vector<ll>a(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		ll ans = a[n-k]-a[0];
		cout << ans << "\n";
	}
}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p=hell){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;ll temp=x+y;temp%=hell;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(ll i=2;i<=15000000;i++)
        if(!prime[i])
        {
            for(ll j=i;j<=15000000;j+=i)
                if(!prime[j])
                    prime[j] = i;
        }
}*/
int main(){
	ios
	ll t = 1,tc = 0;
	//cin >> t;
	//sieve();
	while(t--){
		ll n,k;
		cin >> n >> k;
		vector<ll>a(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		vector<ll>diff;
		for(int i=1;i<n;i++)
			diff.pb(a[i]-a[i-1]);
		sort(all(diff));
		reverse(all(diff));
		ll ans = a[n-1]-a[0];
		for(int i=0;i<k-1;i++)
			ans -= diff[i];
		cout << ans << "\n";
	}
}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p=hell){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;ll temp=x+y;temp%=hell;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(ll i=2;i<=15000000;i++)
        if(!prime[i])
        {
            for(ll j=i;j<=15000000;j+=i)
                if(!prime[j])
                    prime[j] = i;
        }
}*/
int main(){
	ios
	ll t = 1,tc = 0;
	//cin >> t;
	//sieve();
	while(t--){
		ll n,k;
		cin >> n >> k;
		vector<ll>a(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		ll ind = n-1,cur = n-1;
		ll ans = 0;
		while(ind>1)
		{
			if(k==1)
			{
				ans += a[cur]-a[0];
				break;
			}
			if((a[cur]-a[ind]+a[ind-1]-a[0])>(a[cur]-a[ind-1]+a[ind-2]-a[0]))
				ind--;
			else
			{
				ans+= a[cur]-a[ind];
				ind--;
				cur = ind;
				k--;
			}
			if(k==cur+1)
				break;
			if(k==ind+1)
			{
				ans += a[cur]-a[ind];
				break;
			}
		}
		if(n==2 && k==1)
			ans = a[1]-a[0];
		cout << ans << "\n";
	}
}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p=hell){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;ll temp=x+y;temp%=hell;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(ll i=2;i<=15000000;i++)
        if(!prime[i])
        {
            for(ll j=i;j<=15000000;j+=i)
                if(!prime[j])
                    prime[j] = i;
        }
}*/
int main(){
	ios
	ll t = 1,tc = 0;
	//cin >> t;
	//sieve();
	while(t--){
		ll n,k;
		cin >> n >> k;
		vector<ll>a(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		ll ind = n-1,cur = n-1;
		ll ans = 0;
		while(ind>1)
		{
			if(k==1)
			{
				ans += a[cur]-a[0];
				break;
			}
			if((a[cur]-a[ind]+a[ind-1]-a[0])>(a[cur]-a[ind-1]+a[ind-2]-a[0]))
				ind--;
			else
			{
				ans+= a[cur]-a[ind];
				ind--;
				cur = ind;
				k--;
			}
			if(k==cur+1)
				break;
			if(k==ind+1)
			{
				ans += a[cur]-a[ind];
				break;
			}
			if(ind==1)
			{
				ans += a[cur]-a[0];
				break;
			}
		}
		if(n==2 && k==1)
			ans = a[1]-a[0];
		cout << ans << "\n";
	}
}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p=hell){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;x%=p;if(y<0)y+=p;y%=p;ll temp=x+y;temp%=hell;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(ll i=2;i<=15000000;i++)
        if(!prime[i])
        {
            for(ll j=i;j<=15000000;j+=i)
                if(!prime[j])
                    prime[j] = i;
        }
}*/
int main(){
	ios
	ll t = 1,tc = 0;
	//cin >> t;
	//sieve();
	while(t--){
		ll n,k;
		cin >> n >> k;
		vector<ll>a(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		ll ind = n-1,cur = n-1;
		ll ans = 0;
		while(ind>1)
		{

			if(k==1)
			{
				ans += a[cur]-a[0];
				break;
			}
			if((a[cur]-a[ind]+a[ind-1]-a[0])>(a[cur]-a[ind-1]+a[ind-2]-a[0]))
				ind--;
			else
			{
				ans+= a[cur]-a[ind];
				ind--;
				cur = ind;
				k--;
			}
			if(k==ind+1)
				break;
		}
		if(n==2 && k==1)
			ans = a[1]-a[0];
		cout << ans << "\n";
	}
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  if(k == n){
    cout<<'0';
    return 0;
  }
  if(k == 1){
    cout<<arr[n-1] - arr[0];
    return 0;
  }
  if(k == 2){
  int ans = inf;
  rep(i,n){
    ans = min(ans,arr[i] - arr[0] + arr[n-1] - arr[i+1]);
  }
  }
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        //mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //mid -= (maxi - mini);
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    //mid = (l+r)/2;
    if(t == k || (cost == 0 && t<=k)){
      r = mid;
      ans = min(ans,cost);
    }
    else if(t > k)
      l = mid+1;
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  /*if(k == n){
    cout<<'0';
    //return 0;
  }*/
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    mid -= (maxi - mini);
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    mid = (l+r)/2;
    if(t == k || (cost == 0 && t<=k)){
      r = mid;
      ans = min(ans,cost);
    }
    else if(t > k || mid < 0)
      l = mid+1;
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  /*if(k == n){
    cout<<'0';
    //return 0;
  }*/
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    if(t > k)l = mid+1;
    else if(t == k || cost == 0){
      r = mid;
      ans = min(ans,cost);
    }
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  /*if(k == n){
    cout<<'0';
    //return 0;
  }*/
   if(k == 2){
    int ans = inf;
    rep(i,n){
      ans = min(ans,arr[i] - arr[0] + arr[n-1] - arr[i+1]);
    }
  }
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        //mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //mid -= (maxi - mini);
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    //mid = (l+r)/2;
    if(t == k || (cost == 0 && t<=k)){
      r = mid;
      ans = min(ans,cost);
    }
    else if(t > k)
      l = mid+1;
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  multiset<int> s;
  rep(i,n-1)s.insert(arr[i+1] - arr[i]);
  int ans= 0;
  int cnt = n-k;
  for(int i:s){
    ans+=i;
    cnt--;
    if(cnt == 0)break;
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  /*if(k == n){
    cout<<'0';
    //return 0;
  }*/
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    mid = (l+r)/2;
    if(t > k)l = mid+1;
    else if(t == k || cost == 0){
      r = mid;
      ans = min(ans,cost);
    }
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  /*if(k == n){
    cout<<'0';
    //return 0;
  }*/
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        //mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //mid -= (maxi - mini);
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    //mid = (l+r)/2;
    if(t == k || (cost == 0 && t<=k)){
      r = mid;
      ans = min(ans,cost);
    }
    else if(t > k)
      l = mid+1;
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  if(k == n){
    cout<<'0';
    return 0;
  }
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    if(t > k)l = mid+1;
    else if(t == k){
      r = mid;
      ans = min(ans,cost);
    }
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  /*if(k == n){
    cout<<'0';
    //return 0;
  }*/
  if(k == 2){
    int ans = inf;
    rep(i,n-1){
      ans = min(ans,arr[i] - arr[0] + arr[n-1] - arr[i+1]);
    }
    cout<<ans;
    return 0;
  }
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    mid -= (maxi - mini);
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    //mid = (l+r)/2;
    if(t == k && mid >= 0){
      r = (l+r)/2;
      ans = min(ans,cost);
    }
    else if(t > k)
      l = (l+r)/2 +1;
    else{
      r = (l+r)/2;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  if(k == n){
    cout<<'0';
    return 0;
  }
  if(k == 1){
    cout<<arr[n-1] - arr[0];
    return 0;
  }
  if(k == 2){
  int ans = inf;
  rep(i,n-1){
    ans = min(ans,arr[i] - arr[0] + arr[n-1] - arr[i+1]);
  }
  }
  int l = 0,r = inf;
  int ans = inf;
  while(l < r){
    int mid = (l+r)/2;
    int t = 1;
    int maxi = 0,mini = inf;
    int cost = 0;
    rep(i,n){
      int maxi2 = max(maxi,arr[i]);
      int mini2 = min(mini,arr[i]);
      if(maxi2 - mini2 > mid){
        cost+=maxi - mini;
        //mid -= (maxi - mini);
        //if(r == 31)cout<<i;
        t++;
        maxi = arr[i];
        mini = arr[i];
      }
      else{
        maxi = maxi2;
        mini = mini2;
      }
    }
    cost+=maxi - mini;
    //mid -= (maxi - mini);
    //cout<<t<<' '<<l<<' '<<r<<' '<<cost<<endl;
    //mid = (l+r)/2;
    if(t == k || (cost == 0 && t<=k)){
      r = mid;
      ans = min(ans,cost);
    }
    else if(t > k)
      l = mid+1;
    else{
      r = mid;
    }
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define mod 1000000007
#define maxN 1000001
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii >
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(a,b,c) for(int(a) = b;a<=c;a++)
#define repr(a,b,c) for(int(a) = b;a>=c;a--)
#define rep(i,n) for(int(i) = 0;i<n;i++)
#define fir first
#define sec second
#define beg begin()
#define e end()
#define len length()
using namespace std;
using namespace __gnu_pbds;
const int inf = 0x3f3f3f3f3f3f3f3fll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int32_t main(){
  fastIO;
  int n,k;
  cin>>n>>k;
  int arr[n];
  rep(i,n)cin>>arr[i];
  multiset<int> s;
  rep(i,n-1)s.insert(arr[i+1] - arr[i]);
  int ans= 0;
  int cnt = n-k;
  for(int i:s){
    if(!cnt)break;
    ans+=i;
    cnt--;
  }
  cout<<ans;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1,i;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        long long int arr[n];
        for(i=0;i<n;i++)
            cin>>arr[i];
        if(n==1)
            cout<<arr[0]<<endl;
        else
        {
            int diff[n-1];
            for(i=1;i<n;i++)
                diff[i-1]=arr[i]-arr[i-1];
                cout<<diff[i-1]<<endl;
            sort(diff,diff+n-1);
            int p = n-k,sum=0;
            for(i=0;i<p;i++)
                sum+=diff[i];
            cout<<sum<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1,i;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        long long int arr[n];
        for(i=0;i<n;i++)
            cin>>arr[i];
        if(n==1)
            cout<<arr[0]<<endl;
        else
        {
            int diff[n-1];
            for(i=1;i<n;i++)
                diff[i-1]=arr[i]-arr[i-1];
            sort(arr,arr+n);
            int p = n-k,sum=0;
            for(i=0;i<p;i++)
                sum+=diff[i];
            cout<<sum<<endl;
        }
    }
}


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t=1,i;
        //cin>>t;
        while(t--)
        {
            int n,k;
            cin>>n>>k;
            long long int arr[n];
            for(i=0;i<n;i++)
                cin>>arr[i];
            if(n==1)
                cout<<arr[0]<<endl;
            else
            {
                int diff[n-1];
                for(i=1;i<n;i++)
                    diff[i-1]=arr[i]-arr[i-1];
                sort(diff,diff+n-1);
                int p = n-k,sum=0;
                for(i=0;i<p;i++)
                    sum+=diff[i];
                cout<<sum<<endl;
            }
        }
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1,i;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        long long int arr[n];
        for(i=0;i<n;i++)
            cin>>arr[i];
        if(n==1)
            cout<<arr[0]<<endl;
        else
        {
            int diff[n-1];
            for(i=1;i<n;i++)
                diff[i-1]=arr[i]-arr[i-1];
            sort(diff,diff+n-1);
            int p = n-k,sum=0;
            for(i=0;i<p;i++)
                sum+=diff[i];
            cout<<sum<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1,i;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        long long int arr[n];
        for(i=0;i<n;i++)
            cin>>arr[i];
       cout<<arr[n-k]-arr[0]<<endl;
    }
}


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t=1,i;
        //cin>>t;
        while(t--)
        {
            int n,k;
            cin>>n>>k;
            long long int arr[n];
            for(i=0;i<n;i++)
                cin>>arr[i];
            if(n==1)
                cout<<0<<endl;
            else
            {
                int diff[n-1];
                for(i=1;i<n;i++)
                    diff[i-1]=arr[i]-arr[i-1];
                sort(diff,diff+n-1);
                int p = n-k,sum=0;
                for(i=0;i<p;i++)
                    sum+=diff[i];
                cout<<sum<<endl;
            }
        }
    }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                if(k==1){
					lli ma=INT_MIN;
					lli mi=INT_MAX;
					rep(i,n){
						ma=max(ma,a[i]);
						mi=min(mi,a[i]);
					}
					cout<<ma-mi<<endl;
					return 0;
                }
                lli l=0;
                lli r=1e9;
                lli ans=0;
                while(l<=r){
					lli m=(l+r)/2;
					lli st=0;
					lli g=1;
					repp(i,1,n){
						if(a[i]-a[st]>m){
							g++;
							st=i;
							if(g>k){
								break;
							}
						}
					}
					if(g>k){
						l=m+1;
					}
					else{
						r=m-1;
					}
                }
                lli ind=0;
                repp(i,1,n){
					if(a[i]-a[ind]>l){
						ans+=a[i-1]-a[ind];
						ind=i;
					}
                }
                ans+=a[n-1]-a[ind];
                cout<<ans<<endl;

                return 0;
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                if(k==1){
					lli ma=INT_MIN;
					lli mi=INT_MAX;
					rep(i,n){
						ma=max(ma,a[i]);
						mi=min(mi,a[i]);
					}
					cout<<ma-mi<<endl;
					return 0;
                }
                lli l=0;
                lli r=1e9;
                while(l<=r){
					lli m=(l+r)/2;
					lli st=0;
					lli g=1;
					rep(i,n){
						if(a[i]-a[st]>m){
							g++;
							if(g>k){
								break;
							}
							st=i;
						}
					}
					if(g>k){
						l=m+1;
					}
					else{
						r=m-1;
					}
                }
                cout<<l<<endl;

                return 0;
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                if(k==1){
					lli ma=INT_MIN;
					lli mi=INT_MAX;
					rep(i,n){
						ma=max(ma,a[i]);
						mi=min(mi,a[i]);
					}
					cout<<ma-mi<<endl;
					return 0;
                }
                lli l=0;
                lli r=1000000000;
                lli ans=0;
                while(l<r){
					lli m=(l+r)/2;
					lli st=0;
					lli g=1;
					repp(i,1,n){
						if(a[i]-a[st]>m){
							g++;
							st=i;
							if(g>k){
								break;
							}
						}
					}
					if(g>k){
						l=m+1;
					}
					else{
						r=m-1;
					}
                }
                lli ind=0;
                repp(i,1,n){
					if(a[i]-a[ind]>l){
						ans+=a[i-1]-a[ind];
						ind=i;
					}
                }
                ans+=a[n-1]-a[ind];
                cout<<ans<<endl;

                return 0;
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                vector<lli> b;
                rep(i,n-1)b.push_back(a[i+1]-a[i]);
                sort(b.begin(),b.end());
                lli ans=0;
                rep(i,n-k)ans+=b[i];
                cout<<ans<<endl;

                return 0;
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                if(k==1){
					lli ma=INT_MIN;
					lli mi=INT_MAX;
					rep(i,n){
						ma=max(ma,a[i]);
						mi=min(mi,a[i]);
					}
					cout<<ma-mi<<endl;
					return 0;
                }
                lli l=0;
                lli r=1e9;
                lli ans;
                while(l<=r){
					ans=0;
					lli m=(l+r)/2;
					lli st=0;
					lli g=1;
					repp(i,1,n){
						if(a[i]-a[st]>m){
							g++;
							ans+=a[i-1]-a[st];
							if(g>k){
								break;
							}
							st=i;
						}
					}
					if(g>k){
						l=m+1;
					}
					else{
						r=m-1;
					}
                }
                cout<<ans<<endl;

                return 0;
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                if(k==1){
					lli ma=INT_MIN;
					lli mi=INT_MAX;
					rep(i,n){
						ma=max(ma,a[i]);
						mi=min(mi,a[i]);
					}
					cout<<ma-mi<<endl;
					return 0;
                }
                lli l=0;
                lli r=1e9;
                lli ans=0;
                while(l<r){
					lli m=(l+r)/2;
					lli st=0;
					lli g=1;
					repp(i,1,n){
						if(a[i]-a[st]>m){
							g++;
							st=i;
							if(g>k){
								break;
							}
						}
					}
					if(g>k){
						l=m+1;
					}
					else{
						r=m-1;
					}
                }
                lli ind=0;
                repp(i,1,n){
					if(a[i]-a[ind]>l){
						ans+=a[i-1]-a[ind];
						ind=i;
					}
                }
                ans+=a[n-1]-a[ind];
                cout<<ans<<endl;

                return 0;
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli n,t,i,j,k,m;
                cin>>n>>k;
                vector<lli> a(n);
                rep(i,n)cin>>a[i];
                if(k==1){
					lli ma=INT_MIN;
					lli mi=INT_MAX;
					rep(i,n){
						ma=max(ma,a[i]);
						mi=min(mi,a[i]);
					}
					cout<<ma-mi<<endl;
					return 0;
                }
                lli l=0;
                lli r=1e9;
                lli ans;
                while(l<=r){
					ans=0;
					lli m=(l+r)/2;
					lli st=0;
					lli g=1;
					repp(i,1,n){
						if(a[i]-a[st]>m){
							g++;
							ans+=a[i-1]-a[st];
							if(g>k){
								break;
							}
							st=i;
						}
					}
					ans+=a[n-1]-a[st];
					if(g>k){
						l=m+1;
					}
					else{
						r=m-1;
					}
                }
                cout<<ans<<endl;

                return 0;
            }


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

string piiToStr(vector<int> p){
    return to_string(p.front()) + "," + to_string(p.back());
}

unordered_map<string,int> memo;

int dp(int l,int k, const vector<int>& arr){
    if(k == 1)  return memo[piiToStr({l,k})] = arr.back() - arr[l];
    if(memo.find(piiToStr({l,k})) != memo.end() ) return memo[piiToStr({l,k})];
    int path = INT_MAX;
    foriin(i,arr.size()-k+1,l){
        path = min(path,arr[i] - arr[l] + dp(i+1, k-1, arr));
    }
    return memo[piiToStr({l,k})] = path;
}

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0);
    read(arr);
    cout<<dp(0 , k, arr);

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> diff(n,0);
    vector<int> arr(n,0);
    read(arr);
    if(k==1) {
        cout<<arr.back() - arr.front();
        return;
    }

    adjacent_difference(begin(arr), end(arr), begin(diff));
    diff.front() = 0;

    vector<int> pos(n,0);
    iota(begin(pos), end(pos), 0);
    sort(begin(pos), end(pos), [&](auto a, auto b){
        return diff[a] < diff[b];
    });
    pos.push_back(n);
    vector<int> splits(end(pos) - k ,end(pos));
    sort(begin(splits), end(splits));

    int ans = arr[splits.front()-1] - arr.front();
    for(int i = 0;i<splits.size()-1;++i){
        ans += arr[splits[i+1]-1] - arr[splits[i]];
    }
    cout<<ans;

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

int dp(int l,int k, const vector<int>& arr,vector<vector<int>>& memo){
    if(k == 1)  return memo[l][k] = arr.back() - arr[l];
    if(memo[l][k] != -1 ) return memo[l][k];
    int path = INT_MAX;
    foriin(i,arr.size()-k+1,l){
        path = min(path,arr[i] - arr[l] + dp(i+1, k-1, arr, memo));
    }
    return memo[l][k] = path;
}

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0);
    read(arr);
    vector<vector<int>> memo(n,vector<int>(k+1,-1));
    cout<<dp(0 , k, arr, memo);

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> diff(n,0);
    vector<int> arr(n,0);
    read(arr);
    if(k==1) {
        cout<<arr.back() - arr.front();
        return;
    }

    adjacent_difference(begin(arr), end(arr), begin(diff));
    diff.front() = 0;

    vector<int> pos(n,0);
    iota(begin(pos), end(pos), 0);
    sort(begin(pos), end(pos), [&](auto a, auto b){
        return diff[a] < diff[b];
    });
    pos.push_back(n);
    vector<int> splits(end(pos) - k ,end(pos));
    sort(begin(splits), end(splits));

    ll ans = 1ll*arr[(splits.front()>0)*(splits.front()-1)] - arr.front() ;
    for(int i = 0;i<splits.size()-1;++i){
        ans += arr[splits[i+1]-1] - arr[splits[i]];
    }
    cout<<ans;

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

int dp(int l,int k, const vector<int>& arr,vector<vector<int>>& memo,int size){
    if(k == 1)  return memo[k][size] = arr.back() - arr[l];
    if(memo[k][size] != -1 ) return memo[k][size];
    int path = INT_MAX;
    foriin(i,arr.size()-k+1,l){
        path = min(path,arr[i] - arr[l] + dp(i+1, k-1, arr, memo,i-l));
    }
    return memo[k][size] = path;
}

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0);
    read(arr);

    vector<vector<int>> memo(k+1,vector<int>());
    int size = arr.size()+1-k;
    for (int i = 1; i < memo.size(); i++){
        memo[i] = vector<int>(size,-1);
    }

    cout<<dp(0 , k, arr, memo, 0);

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

int dp(int l,int k, const vector<int>& arr,vector<vector<int>>& memo,int disp){
    if(k == 1)  return memo[k][disp] = arr.back() - arr[l];
    if(memo[k][disp] != -1 ) return memo[k][disp];
    int path = INT_MAX;
    foriin(i,arr.size()-k+1,l){
        path = min(path,arr[i] - arr[l] + dp(i+1, k-1, arr, memo,disp+i-l));
    }
    return memo[k][disp] = path;
}

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0);
    read(arr);

    vector<vector<int>> memo(k+1,vector<int>());
    int size = arr.size()+1-k;
    for (int i = 1; i < memo.size(); i++){
        memo[i] = vector<int>(size,-1);
    }

    cout<<dp(0 , k, arr, memo, 0);

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <tuple>
#define print(cont) for (const auto& elem: cont) cout<<elem<<" "; cout<<endl;
#define read(cont) for(auto & a:cont) cin>>a;
#define foreach(elem, cont) for (const auto& elem: cont)
#define forin(i, n) for (int i = 0; i < n; ++i)
#define foriin(i, n, init) for (int i = init; i < n; ++i)
#define ll long long
#define pii pair<int, int>
#define INF INT_MAX
using namespace std;
auto gcd(ll a, ll b) {while (b != 0) {auto t = b;b = a % b;a = t;}return a;}
ll mod = 998244353 ;
ll modpow(ll a,ll b){ if(b==1) return a%mod; return (a % mod * modpow(a,b-1)% mod)% mod; }

void solve(){
    // ifstream in; in.open("input.txt");
    // ofstream out; out.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<int> diff(n,0);
    vector<int> arr(n,0);
    read(arr);
    if(k==1) {
        cout<<arr.back() - arr.front();
        return;
    }

    adjacent_difference(begin(arr), end(arr), begin(diff));
    diff.front() = 0;

    vector<int> pos(n,0);
    iota(begin(pos), end(pos), 0);
    sort(begin(pos), end(pos), [&](auto a, auto b){
        return diff[a] < diff[b];
    });

    vector<int> splits(end(pos) - k ,end(pos));
    sort(begin(splits), end(splits));

    ll ans = 1ll*arr[(splits.front())*(splits.front()-1)] - arr.front() + arr.back() - arr[splits.back()];
    for(int i = 0;i<splits.size()-1;++i){
        ans += arr[splits[i+1]-1] - arr[splits[i]];
    }
    cout<<ans;

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define ll long long
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
   vector<int>v;
    rep(i,0,n){
    cin>>a[i];
    if(i!=0)v.pb(a[i]-a[i-1]);
    }

    if(k==n){cout<<0; return 0;}
    if(k==1){cout<<a[n-1]-a[0]; return 0;}

    sort(v.begin(),v.end());
    int key=v[n-(k)],say=1;
    for(unsigned i=key;i<=v.size();i++)
    {
        if(v[i+1]==v[i])say++;

    }

  //  cout<<key<<"k"<<endl;
    //cout<<say<<"s"<<endl;

    int start=a[0],ans=0;
    rep(i,1,n)
    {
        if(a[i]-a[i-1]>key){ ans+=a[i-1]-start; start=a[i];}
        if(a[i]-a[i-1]==key && say>0){ ans+=a[i-1]-start; start=a[i]; say--;}
    }
    cout<<ans;

return 0;}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M_PI 3.14159265358979323846
const int M = 1e9+7;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);

    int n, m, cnt = 0; cin >> n >> m;
    string s, t; cin >> s >> t;

    vector<int>v,v2;

    int mn = s.size();

    for(int i=0; i<=t.size()-s.size(); ++i)
    {
        cnt = 0;
        for(int j=0; j<s.size(); ++j)
        {
            if(t[i+j] != s[j]) {
                cnt ++; v.push_back(j+1);
            }
        }

        if(mn > cnt){
            mn = cnt;
            if(v2.size()!=0) {v2.clear(); v2 = v;}
            else v2 = v;
        }
        else v.clear();

    }

    cout << mn << endl;

    if(mn==1)return cout << "1" << endl, 0;

    for(int x:v2) cout << x << ' ';
    cout << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M_PI 3.14159265358979323846
const int M = 1e9+7;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);

    int n, m, cnt = 0; cin >> n >> m;
    string s, t; cin >> s >> t;
    if(n==1 && m==1){
        if(s[0]!=t[0]){cout << "1" << endl; cout << "1" << endl; return 0;}
    }
    vector<int>v,v2;

    int mn = s.size();

    for(int i=0; i<=t.size()-s.size(); ++i)
    {
        cnt = 0;
        for(int j=0; j<s.size(); ++j)
        {
            if(t[i+j] != s[j]) {
                cnt ++; v.push_back(j+1);
            }
        }

        if(mn > cnt){
            mn = cnt;
            if(v2.size()!=0) {v2.clear(); v2 = v;}
            else v2 = v;
        }
        else v.clear();

    }

    cout << mn << endl;

    for(int x:v2) cout << x << ' ';
    cout << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M_PI 3.14159265358979323846
const int M = 1e9+7;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);

    int n, m, cnt = 0; cin >> n >> m;
    string s, t; cin >> s >> t;
    if(n==1 && m==1){
        if(s[0]!=t[0])return cout << "1" << endl, 0;
        else return cout << "0" << endl, 0;
    }
    vector<int>v,v2;

    int mn = s.size();

    for(int i=0; i<=t.size()-s.size(); ++i)
    {
        cnt = 0;
        for(int j=0; j<s.size(); ++j)
        {
            if(t[i+j] != s[j]) {
                cnt ++; v.push_back(j+1);
            }
        }

        if(mn > cnt){
            mn = cnt;
            if(v2.size()!=0) {v2.clear(); v2 = v;}
            else v2 = v;
        }
        else v.clear();

    }

    cout << mn << endl;

    for(int x:v2) cout << x << ' ';
    cout << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M_PI 3.14159265358979323846
const int M = 1e9+7;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);

    int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;

    vector<int>v,v2;

    for(int i=0; i<n; ++i) v2.push_back(i+1);

    for(int i=0; i<=t.size()-s.size(); ++i)
    {
         v.clear();
        for(int j=0; j<s.size(); ++j)
        {
            if(t[i+j] != s[j]) {
                v.push_back(j+1);
            }
        }

        if(v.size() < v2.size()) v2 = v;

    }

    cout << v2.size() << endl;

    for(int x:v2) cout << x << ' ';
    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
stack<int> pos, final;
signed main () {
	int n, m;
	cin >> n >> m;
	string a, b;
	cin >> a >> b;
	int ans = 1000000;
	a = ' ' + a;
	b = ' ' + b;
	for (int i = 1; i <= m - n + 1; i ++) {
		while(!pos.empty()) pos.pop();
		int tmp = 0;
		for (int j = 1; j <= n; j++) {
			if (a[j] != b[i + j - 1]) {
				tmp ++;
				pos.push(j);
			}
		}

		if (tmp < ans) {

			while (!final.empty()) final.pop();
			while (!pos.empty()) {
				final.push(pos.top());
				pos.pop();
			}
			ans = tmp;
		}
	}
	cout << ans << endl;
	while (!final.empty()) {
		cout << final.top() << ' ';
		final.pop();
	}
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

vector<int> ans;
string a, b;
int n, k;

void check(int ind)
{
	vector<int> cur;
	for (int i = 0; i < n && i + ind < k; i++)
		if (a[i] != b[i + ind])
			cur.push_back(i);
	if ((int)cur.size() < (int)ans.size())
		ans = cur;
}

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	cin >> n >> k;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
		if (a[i] != b[i])
			ans.push_back(i);

	for (int i = 1; i < k - n + 1; i++)
		check(i);

	cout << ans.size() << endl;
	for (auto i: ans)
		cout << i + 1 << " ";

	return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

vector<int> ans;
string a, b;
int n, k;

void check(int ind)
{
	vector<int> cur;
	for (int i = ind; i < ind + n; i++)
		if (a[i - ind] != b[i])
			cur.push_back(i - ind);
	if (cur.size() < ans.size())
		ans = cur;
}

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	cin >> n >> k;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
		if (a[i] != b[i])
			ans.push_back(i);

	for (int i = 0; i < k; i++)
		check(i);

	cout << ans.size() << endl;
	for (auto i: ans)
		cout << i + 1 << " ";

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

vector<int> ans;
string a, b;
int n, k;

void check(int ind)
{
	vector<int> cur;
	for (int i = ind; i < ind + n; i++)
		if (a[i - ind] != b[i])
			cur.push_back(i - ind);
	if (cur.size() < ans.size())
		ans = cur;
}

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	cin >> n >> k;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
		if (a[i] != b[i])
			ans.push_back(i);

	for (int i = 0; i < k - n; i++)
		check(i);

	cout << ans.size() << endl;
	for (auto i: ans)
		cout << i + 1 << " ";

	return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

vector<int> ans;
string a, b;
int n, k;

void check(int ind)
{
	vector<int> cur;
	for (int i = 0; i < n && i + ind < k; i++)
		if (a[i - ind] != b[i + ind])
			cur.push_back(i - ind);
	if ((int)cur.size() < (int)ans.size())
		ans = cur;
}

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	cin >> n >> k;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
		if (a[i] != b[i])
			ans.push_back(i);

	for (int i = 1; i < k; i++)
		check(i);

	cout << ans.size() << endl;
	for (auto i: ans)
		cout << i + 1 << " ";

	return 0;
}


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

int main()
{
int a,b;
cin>>a>>b;
string s,t;
cin>>s>>t;

int min = a;
int index;

for(int i = 0; i <= b-a; i++)
{ int count = 0;

    for(int j = 0; j < a; j++)
        if(s[j] != t[i+j])
        count++;

    if(count < min){
    min = count;
    index = i;
    }
}

cout<<min<<'\n';

for(int i = 0; i < s.size(); i++)
if(s[i] != t[index+i])
cout<<i+1<<' ';

return 0;
}


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

int main()
{
int a,b;
cin>>a>>b;
char s[a],t[b];

for(int i = 0; i < a; i++)
cin>>s[i];

for(int i = 0; i < b; i++)
cin>>t[i];

int min = a;
int index;

for(int i = 0; i <= b-a; i++)
{   int count = 0;

    for(int j = 0; j < a; j++)
        if(s[j] != t[i+j])
        count++;

    if(count < min){
    min = count;
    index = i;
    }
}

cout<<min<<'\n';

for(int i = 0; i < a; i++)
if(s[i] != t[index+i])
cout<<i+1<<' ';

return 0;
}


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

int main()
{
int a,b;
cin>>a>>b;
string s,t;
cin>>s>>t;

int min = a;
int index;

for(int i = 0; i <= b-a; i++)
{ int count = 0;

    for(int j = 0; j < a; j++)
        if(s[j] != t[i+j])
        count++;

    if(count < min){
    min = count;
    index = i;
    }
}

cout<<min<<'\n';

for(int i = 0; i < s.size(); i++)
if(s[i] != t[index+i])
cout<<index+i<<' ';

return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
	char m[1001],n[1001];
	int a,b;
	scanf("%d %d",&a,&b);
	scanf("%s",&m);
	scanf("%s",&n);
	int lenm=strlen(m);
	int lenn=strlen(n);
	int c,max=0,pos=0;
	for(int i=0;i<=lenn-lenm;i++){
		c=0;
		for(int j=0;j<lenm;j++){
			if(m[j]==n[i+j]){
				c++;
			}
		}
		if(c>max){
			max=c;
			pos=i;
		}
	}
	printf("%d\n",lenm-c);
	for(int i=0;i<lenm;i++){
		if(m[i]!=n[i+pos]){
			printf("%d ",i+1);
		}
	}
	return 0;
}


/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 11/2/2019 10:33:04 AM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int MMAX = 0x7fffffff;
const int INF = 0xfffffff;
const int mod = 1e9+7;
ostream& operator <<(ostream &out, pii &p){
	out<<p.first<<" "<<p.second;
}
istream& operator >>(istream &in, pii &p){
	in>>p.first>>p.second;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\LENOVO\\Desktop\\out.txt","w",stdout);
	int a,b;
	string m,n;
	cin>>a>>b>>m>>n;
	int c,max=0,pos=0;
	for(int i=0;i<=n.size()-m.size();i++){
		c=0;
		for(int j=0;j<m.size();j++){
			if(m[j]==n[i+j]) {
				c++;
			}
		}
		if(c>max){
			max=c;
			pos=i;
		}
	}
	cout<<m.size()-max<<endl;
	for(int i=0;i<m.size();i++){
		if(m[i]!=n[i+pos]){
			cout<<i+1<<" ";
		}
	}
	cout<<endl;
	return 0;
}


/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 10/14/2019 10:02:54 PM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int MMAX = 0x7fffffff;
const int INF = 0xfffffff;
const int mod = 1e9+7;
char n[1010],m[1010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\LENOVO\\Desktop\\out.txt","w",stdout);
	int a,b;cin>>a>>b>>n>>m;
	int max=0,pos=0;
	for(int i=0;i<=b-a;i++){
		int ans=0;
		for(int j=0;j<a;j++){
			if(m[i+j]==n[j]){
				ans++;
			}
		}
		if(ans>max){
			max=ans;
			pos=i;
		}
	}
	cout<<a-max<<endl;
	for(int i=pos;i<a+pos;i++){
		if(m[i]!=n[i-pos]){
			printf("%d ",i-pos+1);
		}
	}
	return 0;
}


/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 10/14/2019 10:02:54 PM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int MMAX = 0x7fffffff;
const int INF = 0xfffffff;
const int mod = 1e9+7;
char n[1010],m[1010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\LENOVO\\Desktop\\out.txt","w",stdout);
	int a,b;cin>>a>>b>>n>>m;
	int max=0,pos=0;
	for(int i=0;i<=b-a;i++){
		int ans=0;
		for(int j=0;j<a;j++){
			if(m[i+j]==n[j]){
				ans++;
			}
		}
		if(ans>max){
			max=ans;
			pos=i;
		}
	}
	cout<<a-max<<endl;
	int j=0;
	for(int i=pos;i<a+pos;i++){
		if(m[i]!=n[j]){
			printf("%d ",j+1);
		}
		j++;
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
	char m[1001],n[1001];
	int a,b;
	scanf("%d %d",&a,&b);
	scanf("%s",&m);
	scanf("%s",&n);
	int lenm=strlen(m);
	int lenn=strlen(n);
	int c,max=0,pos=0;
	for(int i=0;i<=lenn-lenm;i++){
		c=0;
		for(int j=0;j<lenm;j++){
			if(m[j]==n[i+j]){
				c++;
			}
		}
		if(c>max){
			max=c;
			pos=i;
		}
	}
	printf("%d\n",lenm-max);
	if(lenm-c==0){printf("0\n");
	}
	else{
	for(int i=0;i<lenm;i++){
		if(m[i]!=n[i+pos]){
			printf("%d ",i+1);}
		}
	}
	return 0;
}


/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 10/14/2019 10:02:54 PM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int MMAX = 0x7fffffff;
const int INF = 0xfffffff;
const int mod = 1e9+7;
char n[1010],m[1010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\LENOVO\\Desktop\\out.txt","w",stdout);
	int a,b;cin>>a>>b>>n>>m;
	int max=0,pos;
	for(int i=0;i<=b-a;i++){
		int ans=0;
		for(int j=0;j<a;j++){
			if(m[i+j]==n[j]){
				ans++;
			}
		}
		if(ans>max){
			max=ans;
			pos=i;
		}
	}
	cout<<a-max<<endl;
	int j=0;
	for(int i=pos;i<b;i++){
		if(j>=a) break;
		if(m[i]!=n[j]){
			cout<<j+1<<" ";
		}
		j++;
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
	char m[1001],n[1001];
	int a,b;
	scanf("%d %d",&a,&b);
	scanf("%s",&m);
	scanf("%s",&n);
	int lenm=strlen(m);
	int lenn=strlen(n);
	int c,max=0,pos=0;
	for(int i=0;i<=lenn-lenm;i++){
		c=0;
		for(int j=0;j<lenm;j++){
			if(m[j]==n[i+j]){
				c++;
			}
		}
		if(c>max){
			max=c;
			pos=i;
		}
	}
	printf("%d\n",lenm-c);
	for(int i=0;i<lenm;i++){
		if(m[i]!=n[i+pos]){
			printf("%d",i+1);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
	char m[1001],n[1001];
	int a,b;
	scanf("%d %d",&a,&b);
	scanf("%s",&m);
	scanf("%s",&n);
	int lenm=strlen(m);
	int lenn=strlen(n);
	int c,max=0,pos=0;
	for(int i=0;i<=lenn-lenm;i++){
		c=0;
		for(int j=0;j<lenm;j++){
			if(m[j]==n[i+j]){
				c++;
			}
		}
		if(c>max){
			max=c;
			pos=i;
		}
	}
	printf("%d\n",lenm-max);
	{
	for(int i=0;i<lenm;i++){
		if(m[i]!=n[i+pos]){
			printf("%d ",i+1);}
		}
	}
	return 0;
}


/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 10/14/2019 10:02:54 PM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int MMAX = 0x7fffffff;
const int INF = 0xfffffff;
const int mod = 1e9+7;
char n[1010],m[1010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\LENOVO\\Desktop\\out.txt","w",stdout);
	int a,b;cin>>a>>b>>n>>m;
	int max=0,pos=0;
	for(int i=0;i<=b-a;i++){
		int ans=0;
		for(int j=0;j<a;j++){
			if(m[i+j]==n[j]){
				ans++;
			}
		}
		if(ans>max){
			max=ans;
			pos=i;
		}
	}
	cout<<a-max<<endl;
	int j=0;
	for(int i=pos;i<b;i++){
		if(j>=a) break;
		if(m[i]!=n[j]){
			cout<<j+1<<" ";
		}
		j++;
	}
	return 0;
}


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

int main(){
	int n,m,max,k,i,a;
	cin>>n>>m;
	string s,t;

	cin>>s;
	cin>>t;

	int count[m-n+1];
	for(i=0;i<(m-n+1);i++)
	count[i]=0;

			for(i=0;i<(m-n+1);i++)
			{
			    for(int j=i;j<i+n;j++)
			    {
			        if(s[j-i]==t[j])
			      count[i]++;
			    }
			}
		max =count[0];
		for(int i=0;i<(m-n+1);i++)
		{
		    if(count[i]>=max)
		    {
		        max=count[i];
		        k=i;

		    }
		}
	cout<<n-max<<endl;
	for(int j=k;j<k+n;j++)
	{

	    if(s[j-k]!=t[j])
	    { a=j-k+1;
          cout<<a<<" ";
	    }
	}
}


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

int main(){
	int n,m,max,k,i,a;
	cin>>n>>m;
	string s,t;

	cin>>s;
	cin>>t;

	int count[m+n-1];
	for(i=0;i<(m+n-1);i++)
	count[i]=0;

			for(i=0;i<(m+n-1);i++)
			{
			    for(int j=i;j<i+n;j++)
			    {
			        if(s[j-i]==t[j])
			      count[i]++;
			    }
			}
		max =count[0];
		for(int i=0;i<(m+n-1);i++)
		{
		    if(count[i]>=max)
		    {
		        max=count[i];
		        k=i;

		    }
		}
	cout<<n-max<<endl;
	for(int j=k;j<k+n;j++)
	{

	    if(s[j-k]!=t[j])
	    { a=j-k+1;
          cout<<a<<" ";
	    }
	}
}


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

int main(){
	int n,m,max,k,i,a;
	cin>>n>>m;
	string s,t;

	cin>>s;
	cin>>t;

	int count[m+n+1];
	for(i=0;i<(m+n-1);i++)
	count[i]=0;

			for(i=0;i<(m+n-1);i++)
			{
			    for(int j=i;j<i+n;j++)
			    {
			        if(s[j-i]==t[j])
			      count[i]++;
			    }
			}
		max =count[0];
		for(int i=0;i<(m+n-1);i++)
		{
		    if(count[i]>max)
		    {
		        max=count[i];
		        k=i;

		    }
		}
	cout<<n-max<<endl;
	for(int j=k;j<k+n;j++)
	{

	    if(s[j-k]!=t[j])
	    { a=j-k+1;
          cout<<a<<" ";
	    }
	}
}


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

int main(){
	int n,m,max,k,i,a;
	cin>>n>>m;
	string s,t;

	cin>>s;
	cin>>t;

	int count[m-n+1];
	for(i=0;i<(m+n-1);i++)
	count[i]=0;

			for(i=0;i<(m+n-1);i++)
			{
			    for(int j=i;j<i+n;j++)
			    {
			        if(s[j-i]==t[j])
			      count[i]++;
			    }
			}
		max =count[0];
		for(int i=0;i<(m+n-1);i++)
		{
		    if(count[i]>max)
		    {
		        max=count[i];
		        k=i;

		    }
		}
	cout<<n-max<<endl;
	for(int j=k;j<k+n;j++)
	{

	    if(s[j-k]!=t[j])
	    { a=j-k+1;
          cout<<a<<" ";
	    }
	}
}


#include <bits/stdc++.h>
#include <cstring>
#define ll long long
#define fi first
#define se second
using namespace std;
int main()
{
    string a,b;
    int n,m;
    cin>>n>>m>>a>>b;
    int ans = int(1e8);
    vector<int> vec1,vec2;
    for(int i = 0;i<m;i++)
    {

        if(a[0] == b[i])
        {
            vec1.clear();
            for(int j = 1;j + i<m && j < n;j++)
            {
                if(a[j] != b[j+i])
                {
                    vec1.push_back(j+1);
                }
            }
            if(vec1.size() < vec2.size() || vec2.size() == 0)
            {
                vec2 = vec1;
            }
        }

    }
    if(vec2.size() == 0)
    {
        cout<<n<<endl;
        for(int i = 1;i<=n;i++) cout<<i<<" ";
    }
    else
    {
        cout<<vec2.size()<<endl;
        for(int x : vec2) cout<<x<<" ";
    }
    return 0 ;
}


#include <bits/stdc++.h>
#include <cstring>
#define ll long long
#define fi first
#define se second
using namespace std;
int main()
{
    string a,b;
    int n,m;
    cin>>n>>m>>a>>b;
    vector<int> vec1,vec2;
    int mx = 0,cur = 0;;
    for(int i = 1;i<=n;i++) vec2.push_back(i);
    for(int i = 0;i<m-n+1;i++)
    {
        vec1.clear();
        for(int j  =0;i+j<m&& j<n;j++)
        {
            if(a[j] != b[i+j]) vec1.push_back(j+1);
        }
//        for(int i =0;i<vec1.size();i++) cout<<vec1[i]<<endl;
//        cout<<endl;
        if(vec1.size() < vec2.size())
        {
            vec2.swap(vec1);
        }
    }
    cout<<vec2.size()<<endl;
    for(int x: vec2)
    {
        cout<<x<<" ";
    }
    return 0 ;
}


#include <bits/stdc++.h>
#include <cstring>
#define ll long long
#define fi first
#define se second
using namespace std;
int main()
{
    string a,b;
    int n,m;
    cin>>n>>m>>a>>b;
    int ans = int(1e8);
    vector<int> vec1,vec2;
    int mx = 0;
    for(int i = 0;i<m;i++)
    {

        if(a[0] == b[i])
        {
            vec1.clear();
            int cur = 1;
            for(int j = 1;j + i<m && j < n;j++)
            {
                if(a[j] != b[j+i])
                {
                    vec1.push_back(j+1);
                }
                else cur++;
            }
            if(cur > mx)
            {
                mx  =cur;
                vec2 = vec1;
            }
        }

    }
    if(mx == 0)
    {
        cout<<n<<endl;
        for(int i  =1;i<=n;i++)
        {
            cout<<i<<" ";
        }
    }
    else
    {
        cout<<vec2.size()<<endl;
        for(int x : vec2)
        {
            cout<<x<<" ";
        }
    }
    return 0 ;
}