#include <stdio.h>
#include <string.h>
int n, m;
int loc[10002];
char a[10002];
int l[30001];
int r[30001];
int k[30001];

void shiftgo(int left, int right, int num)
{
    int temp[10002];
    int i;
    num=num%(right-left+1);
    for(i=left ; i<=right ; i++)
    {
        temp[i]=loc[i];
    }
    for(i=left ; i<=left+num-1 ; i++)
    {
        loc[i]=temp[i-num+right-left+1];
    }
    for(i=left+num ; i<=right ; i++)
    {
        loc[i]=temp[i-num];
    }
}

int main(void)
{
    scanf("%s",&a[1]);
    int i;
    int n=strlen(&a[1]);
    for(i=1 ; i<=n ; i++)
    {
        loc[i]=i;
    }
    scanf("%d",&m);
    for(i=1 ; i<=m ; i++)
    {
        scanf("%d %d %d",&l[i],&r[i],&k[i]);
    }
    for(i=1 ; i<=m ; i++)
    {
        shiftgo(l[i],r[i],k[i]);
    }
    for(i=1 ; i<=n ; i++)
    {
        printf("%c",a[loc[i]]);
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker,"/STACK:256000000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <cassert>
#include <string>
using namespace std;

#define INF 1000000000
#define lint long long
#define pb push_back
#define MOD 1000000007
#define mp make_pair

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		k %= (r - l + 1);
		--l;
		--r;
		string str;
		int ind = r + 1 - k;
		if (ind > r)ind = l;
		for (int i = l; i <= r; ++i) {
			str += s[ind];
			++ind;
			if (ind > r) ind = l;
		}

		for (int i = l; i <= r; ++i) {
			s[i] = str[i - l];
		}

		//cout << s << endl;
	}
	cout << s;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker,"/STACK:256000000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <cassert>
#include <string>
using namespace std;

#define INF 1000000000
#define lint long long
#define pb push_back
#define MOD 1000000007
#define mp make_pair

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		k %= (r - l + 1);
		--l;
		--r;
		string str;
		int ind = r + 1 - k;
		for (int i = l; i <= r; ++i) {
			str += s[ind];
			++ind;
			if (ind > r) ind = l;
		}

		for (int i = l; i <= r; ++i) {
			s[i] = str[i - l];
		}

		//cout << s << endl;
	}
	cout << s;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,s1,s3,s4,s2;
    cin >> s;
    int l,r,k,m;
    cin >> m;
    while (m--)
    {
        cin >> l >> r >> k;
        k=k%(r-l+1);
        s1=s.substr(0,l-1);
        s2=s.substr(l-1,r-l+1-k);
        s3=s.substr(r-k,k);
        s4=s.substr(r,s.size()-r);

        s=s1+s3+s2+s4;
    }
    cout << s;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,s1,s3,s4,s2;
    cin >> s;
    int l,r,k,m;
    cin >> m;
    while (m--)
    {
        cin >> l >> r >> k;
        k=k%(r-l+1);
        s1=s.substr(0,l-1);
        s2=s.substr(l-1,r-l+1-k);
        s3=s.substr(r-k-1,k);
        s4=s.substr(r,s.size()-r);

        s=s1+s3+s2+s4;
    }
    cout << s;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <limits>
#define dbg(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
template<class T>void dbgarr(T *a, int s, int t) { for (int i = s; i <= t; i++)cerr << a[i] << ' '; cerr << endl; }
template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y); }

int main()
{
    string s;
    cin>>s;
    int m;
    cin>>m;
    while(m--)
    {
        int l,r,k;
        cin>>l>>r>>k;
        k%=(r-l+1);
        l--;
        r--;
        while(k--)
        {
            s=s.substr(0,l)+s[r]+s.substr(l+1,r-l)+s.substr(r+1,s.size()-r-1);
        }

    }
    cout<<s<<endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <limits>
#define dbg(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
template<class T>void dbgarr(T *a, int s, int t) { for (int i = s; i <= t; i++)cerr << a[i] << ' '; cerr << endl; }
template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y); }

int main()
{
    string s;
    cin>>s;
    int m;
    cin>>m;
    while(m--)
    {
        int l,r,k;
        cin>>l>>r>>k;
        k%=(r-l+1);
        l--;
        r--;
        string temp;
        int x=r;
        s=s.substr(0,l)+s.substr(r-k+1,k)+s.substr(l,r-l-k+1)+s.substr(r+1,s.size()-r-1);

    }
    cout<<s<<endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <limits>
#define dbg(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
template<class T>void dbgarr(T *a, int s, int t) { for (int i = s; i <= t; i++)cerr << a[i] << ' '; cerr << endl; }
template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y); }

int main()
{
    string s;
    cin>>s;
    int m;
    cin>>m;
    while(m--)
    {
        int l,r,k;
        cin>>l>>r>>k;
        k%=(r-l+1);
        l--;
        r--;
        while(k--)
        {
            s=s.substr(0,l)+s[r]+s.substr(l,r-l)+s.substr(r+1,s.size()-r-1);
            //cout<<s.substr(0,l)<<' '<<s[r]<<' '<<s.substr(l+1,r-l)<<' '<<s.substr(r+1,s.size()-r-1)<<endl;
        }

    }
    cout<<s<<endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <limits>
#define dbg(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
template<class T>void dbgarr(T *a, int s, int t) { for (int i = s; i <= t; i++)cerr << a[i] << ' '; cerr << endl; }
template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y); }

int main()
{
    string s;
    cin>>s;
    int m;
    cin>>m;
    while(m--)
    {
        int l,r,k;
        cin>>l>>r>>k;
        k%=(r-l+1);
        l--;
        r--;
        while(k--)
        {
            s=s.substr(0,l)+s[r]+s.substr(l,r-l)+s.substr(r+1,s.size()-r-1);
            cout<<s.substr(0,l)<<' '<<s[r]<<' '<<s.substr(l+1,r-l)<<' '<<s.substr(r+1,s.size()-r-1)<<endl;
        }

    }
    cout<<s<<endl;
    return 0;
}


#include<stdio.h>
char s[10005],c[1005];
void move(int l,int r,int k)
{
    int t=r-l+1;
    for(int i=l; i<=r; i++)
        c[i]=s[(i+t-k)%t];
    for(int i=l; i<=r; i++)
        s[i]=c[i];
}
int main()
{
    int l,r,k,m;
    gets(s);
    scanf("%d",&m);
    while(m--) {
        scanf("%d%d%d",&l,&r,&k);
        move(l-1,r-1,k);
    }
    puts(s);
}


#include<stdio.h>
char s[10005],c[10005];
void move(int l,int r,int k)
{
    int t=r-l+1;
    for(int i=l; i<=r; i++)
        c[i]=s[(i+t-k)%t];
    for(int i=l; i<=r; i++)
        s[i]=c[i];
}
int main()
{
    int l,r,k,m;
    gets(s);
    scanf("%d",&m);
    while(m--) {
        scanf("%d%d%d",&l,&r,&k);
        move(l-1,r-1,k);
    }
    puts(s);
}


#include<stdio.h>
char c[10005];
void shift(char *s,int len,int k)
{
	for(int i=0; i<len; i++)
		c[(i+k)%len]=s[i];
	for(int i=0; i<len; i++)
		s[i]=c[i];
}
int main()
{
	int l,r,k,m;
	char s[10005];
	gets(s);
	scanf("%d",&m);
	while(m--) {
		scanf("%d%d%d",&l,&r,&k);
		shift(s+l-1,r-l+1,k);
	}
	puts(s);
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>

using namespace std;

char st[100002];
vector <char> st2;

int main()
{
	char x = '.';
	int n = 1;
	while(x != '\n')
	{
		cin>>noskipws >> x;
		st[n] = x;
		n++;
	}
	char temp;
	int t;
	int l,r,k;
	int j1;
	int d = 1;
	cin >> skipws>>t;
	for (int i = 0; i < t; ++i)
	{
		cin >>skipws >>l >> r>>k;
		k = k%(r-l+1);
		for (int j = l; j < l+k; ++j)
		{
			st2.push_back(st[j]);
		}
		for (int j = r-k; j >=l; --j)
		{
			temp = st[j+k];
			st[j+k] = st[j];
			st[j] = temp;

		}
		for (int j = r-k+1; j <=r; ++j)
		{
			st[j] = st2[j-r+k-1];
		}
		st2.clear();

			for (int j = 1; j < n; ++j)
		{
			cout << st[j];
		}
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>

using namespace std;

char st[100002];
vector <char> st2;

int main()
{
	char x = '.';
	int n = 1;
	while(x != '\n')
	{
		cin>>noskipws >> x;
		st[n] = x;
		n++;
	}
	char temp;
	int t;
	int l,r,k;
	int j1;
	int d = 1;
	cin >> skipws>>t;
	for (int i = 0; i < t; ++i)
	{
		cin >>skipws >>l >> r>>k;
		k = k%(r-l+1);
		for (int j = l; j < l+k; ++j)
		{
			st2.push_back(st[j]);
		}
		for (int j = r-k; j >=l; --j)
		{
			temp = st[j+k];
			st[j+k] = st[j];
			st[j] = temp;

		}
		for (int j = r-k+1; j <=r; ++j)
		{
			st[j] = st2[j-r+k-1];
		}
		st2.clear();

			for (int j = 1; j < n; ++j)
		{
			cout << st[j];
		}
	}

	system("pause");
	return 0;
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>

using namespace std;

char st[100002];
vector <char> st2;

int main()
{
	char x = '.';
	int n = 1;
	while(x != '\n')
	{
		cin>>noskipws >> x;
		st[n] = x;
		n++;
	}
	char temp;
	int t;
	int l,r,k;
	int j1;
	int d = 1;
	cin >> skipws>>t;
	for (int i = 0; i < t; ++i)
	{
		cin >>skipws >>l >> r>>k;
		k = k%(r-l);
		for (int j = l; j < l+k; ++j)
		{
			st2.push_back(st[j]);
		}
		for (int j = r-k; j >=l; --j)
		{
			temp = st[j+k];
			st[j+k] = st[j];
			st[j] = temp;

		}
		for (int j = r-k+1; j <=r; ++j)
		{
			st[j] = st2[j-r+k-1];
		}
		st2.clear();
	}

	for (int j = 1; j < n; ++j)
		{
			cout << st[j];
		}
	return 0;
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>

using namespace std;

char st[100002];
vector <char> st2;

int main()
{
	char x = '.';
	int n = 1;
	while(x != '\n')
	{
		cin>>noskipws >> x;
		st[n] = x;
		n++;
	}
	char temp;
	int t;
	int l,r,k;
	int j1;
	int d = 1;
	cin >> skipws>>t;
	for (int i = 0; i < t; ++i)
	{
		cin >>skipws >>l >> r>>k;
		k = k%(r-l+1);
		for (int j = l; j < l+k; ++j)
		{
			st2.push_back(st[j]);
		}
		for (int j = r-k; j >=l; --j)
		{
			temp = st[j+k];
			st[j+k] = st[j];
			st[j] = temp;

		}
		for (int j = r-k+1; j <=r; ++j)
		{
			st[j] = st2[j-r+k-1];
		}
		st2.clear();
	}
	return 0;
	for (int j = 1; j < n; ++j)
		{
			cout << st[j];
		}
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>

using namespace std;

char st[100002];
vector <char> st2;

int main()
{
	char x = '.';
	int n = 1;
	while(x != '\n')
	{
		cin>>noskipws >> x;
		st[n] = x;
		n++;
	}
	char temp;
	int t;
	int l,r,k;
	int j1;
	int d = 1;
	cin >> skipws>>t;
	for (int i = 0; i < t; ++i)
	{
		cin >>skipws >>l >> r>>k;
		k = k%(r-l+1);
		for (int j = r-k+1; j <= r; ++j)
		{
			st2.push_back(st[j]);
		}
		for (int j = r; j >= l+k; --j)
		{
			st[j] = st[j-k];
		}
		for (int j = l; j < l+k; ++j)
		{
			st[j] = st2[j-l];
		}
		st2.clear();

	}

	for (int j = 1; j < n; ++j)
		{
			cout << st[j];
		}

	return 0;
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>

using namespace std;

char st[100002];
vector <char> st2;

int main()
{
	char x = '.';
	int n = 1;
	while(x != '\n')
	{
		cin>>noskipws >> x;
		st[n] = x;
		n++;
	}
	char temp;
	int t;
	int l,r,k;
	int j1;
	int d = 1;
	cin >> skipws>>t;
	for (int i = 0; i < t; ++i)
	{
		cin >>skipws >>l >> r>>k;
		k = k%(r-l+1);
		for (int j = l; j < l+k; ++j)
		{
			st2.push_back(st[j]);
		}
		for (int j = r-k; j >=l; --j)
		{
			temp = st[j+k];
			st[j+k] = st[j];
			st[j] = temp;

		}
		for (int j = r-k+1; j <=r; ++j)
		{
			st[j] = st2[j-r+k-1];
		}
		st2.clear();
	}

	for (int j = 1; j < n; ++j)
		{
			cout << st[j];
		}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<cstring>
#include<vector>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
	char a[10000];
	char b[10000];
	int n;

	int i;
	long long int l,r,k;
    cin>>a;
	cin>>n;
	int count=0;

		strcpy(b,a);

	for (int j = 0; j < n; j++)
	{   cin>>l>>r>>k;
	if (strlen(a)==1)
	{
		cout<<a;
		return 0;
	}else{
		for ( i = 0; i < strlen(a); i++){

		 if (i<l-1)
		 {
			 b[i]=a[i];
		 }else if(i>=l-1&&i<k+l-1){
			 b[i]=a[r-k+count];
			 count++;
		 }else if (i>=k+l-1&&i<=r-1)
		 {
			 b[i]=a[i-k];
		 }else
		 {
			 b[i]=a[i];
		 }
	  }
		strcpy(a,b);
		count=0;
	}
	}
	cout<<a;

	cin>>n;

return 0;
}


#include<stdio.h>
#include<iostream>
#include<cstring>
#include<vector>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
	char a[10000];
	char b[10000];
	int n;

	int i;
	long long int l,r,k;
    cin>>a;
	cin>>n;
	int count=0;

		strcpy(b,a);

	for (int j = 0; j < n; j++)
	{   cin>>l>>r>>k;
		for ( i = 0; i < strlen(a); i++){

		 if (i<l-1)
		 {
			 b[i]=a[i];
		 }else if(i>=l-1&&i<k+l-1){
			 b[i]=a[r-k+count];
			 count++;
		 }else if (i>=k+l-1&&i<=r-1)
		 {
			 b[i]=a[i-k];
		 }else
		 {
			 b[i]=a[i];
		 }
	  }
		strcpy(a,b);
		count=0;
	}
	cout<<a;

	cin>>n;

return 0;
}


#include<stdio.h>
#include<iostream>
#include<cstring>
#include<vector>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
	char a[20000];
	char b[20000];
	int n;

	int i;
	long long int l,r,k;
    cin>>a;
	cin>>n;
	int count=0;

		strcpy(b,a);

	for (int j = 0; j < n; j++)
	{   cin>>l>>r>>k;
	    k=k%(r-l+1);
	if (strlen(a)==1)
	{
		cout<<a;
		return 0;
	}else{
		for ( i = 0; i < strlen(a); i++){

		 if (i<l-1)
		 {
			 b[i]=a[i];
		 }else if(i>=l-1&&i<k+l-1){
			 b[i]=a[r-k+count];
			 count++;
		 }else if (i>=k+l-1&&i<=r-1)
		 {
			 b[i]=a[i-k];
		 }else
		 {
			 b[i]=a[i];
		 }
	  }
		strcpy(a,b);
		count=0;
	}
	}
	cout<<a;

	cin>>n;

return 0;
}


#include<stdio.h>
#include<iostream>
#include<cstring>
#include<vector>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
	char a[10000];
	char b[10000];
	int n;

	int i;
	long long int l,r,k;
    cin>>a;
	cin>>n;
	int count=0;

		strcpy(b,a);

	for (int j = 0; j < n; j++)
	{   cin>>l>>r>>k;
	    k=k%(r-l+1);
	if (strlen(a)==1)
	{
		cout<<a;
		return 0;
	}else{
		for ( i = 0; i < strlen(a); i++){

		 if (i<l-1)
		 {
			 b[i]=a[i];
		 }else if(i>=l-1&&i<k+l-1){
			 b[i]=a[r-k+count];
			 count++;
		 }else if (i>=k+l-1&&i<=r-1)
		 {
			 b[i]=a[i-k];
		 }else
		 {
			 b[i]=a[i];
		 }
	  }
		strcpy(a,b);
		count=0;
	}
	}
	cout<<a;

	cin>>n;

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int n;
    cin >> n;

    for (int i = 0, l, r, k; i < n; i++)
    {
        cin >> l >> r >> k;
        l--;
        r--;
        rotate(s.begin() + l, s.begin() + r + 1 - k, s.begin() + r + 1);
    }

    cout << s;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int n;
    cin >> n;

    for (int i = 0, l, r, k; i < n; i++)
    {
        cin >> l >> r >> k;
        k %= (r - l + 1);
        l--;
        r--;
        rotate(s.begin() + l, s.begin() + r + 1 - k, s.begin() + r + 1);
    }

    cout << s;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
// yes ! =D
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#include<cmath>
using namespace std;
#define mp make_pair
#define eps 1e-6
int newpos[100005];
int pos[100005];
int main() {
	//freopen("a.txt", "rt", stdin);
	string s ;
	int n , a , b , c ;

	cin >> s;
	for ( int i = 0 ; i < s.length() ; i++){
		newpos[i] = i ;
		pos[i]=i;
	}
	scanf("%d",&n);
	for ( int i = 0 ; i< n ; i++) {
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;

		for ( int  j = a ; j<=b ; j++ ){
			int p = j + c ;

			if(p > b )
				p = a +(p - b-1);

			newpos[p] = pos[j] ;

		}

		for ( int j = 0 ; j < s.length() ; j++ ) {
			pos[j] = newpos[j];
		}
	}

	for ( int i = 0 ; i <s.length() ; i++){
		printf("%c",s[pos[i]]);
	}
	puts("");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
// yes ! =D
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#include<cmath>
using namespace std;
#define mp make_pair
#define eps 1e-6
int newpos[100005];
int pos[100005];
int main() {
	//freopen("a.txt", "rt", stdin);
	string s ;
	int n , a , b , c ;

	cin >> s;
	for ( int i = 0 ; i < s.length() ; i++){
		newpos[i] = i ;
		pos[i]=i;
	}
	scanf("%d",&n);
	for ( int i = 0 ; i< n ; i++) {
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;
		int tmp = b-a +1 ;
		c=c%tmp;

		for ( int  j = a ; j<=b ; j++ ){
			int p = j + c ;
			if(p > b )
				p = a +(p - b-1);

			newpos[p] = pos[j] ;
		}

		for ( int j = 0 ; j < s.length() ; j++ ) {
			pos[j] = newpos[j];
		}
	}

	for ( int i = 0 ; i <s.length() ; i++){
		printf("%c",s[pos[i]]);
	}
	puts("");
	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;
int main(){

	string word;
	cin >> word;
	long long m;
	long long l, r, k;
	cin >> m;

	for (long long i = 1; i <= m; i++){

		cin >> l >> r >> k;
		k = k % (r - l+1);
		rotate(word.begin()+l-1, word.begin() +r-k, word.begin()+r);

	}

	cout << word;
	//system("pause");
	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;
int main(){

	string word;
	cin >> word;
	long long m;
	long long l, r, k;
	cin >> m;

	for (long long i = 1; i <= m; i++){

		cin >> l >> r >> k;
		k = k % (r - l+1);
		rotate(word.begin()+l-1, word.begin() +r-k, word.begin()+r);

	}

	cout << word;
	system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <climits>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define for1(i, n) for (int i = 1; i <= (int)n; i++)
#define forq(i, s, t) for (int i = s; i <= t; i++)
#define ford(i, s, t) for (int i = s; i >= t; i--)
#define mk make_pair
#define inb push_back
#define outb pop_back
#define ump unordered_map
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define randint(x,y)
#define randlong(x, y)
#define TASK ""

const double eps = 1e-15;
const double pi = acos(-1.0);

const int MAXN = (int)1e5 + 7;
const int INF = (ll)2e9;
const ll LINF = (ll)8e18;
const int MOD = (ll)1e9 + 7;

void gen();
int solve();

int main()
{
#ifdef _DEBUG
    gen();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("test.txt", "w", stderr);
    double tstart = TIME;
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
#ifdef _DEBUG
    double tend = TIME;
    cerr << tend - tstart << " s.\n";
#endif
    return 0;
}

void gen()
{
    freopen("input.txt", "a+", stdout);
    srand(time(0));
    return;
}

int solve()
{
    string s;
    cin >> s;
    char s1[MAXN];
    memset(s1, '0', MAXN);
    int m;
    cin >> m;
    while (m--)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        k = k % (r - l + 1);
        int le = r - l + 1;
        for (int i = l; i <= r; i++)
            s1[i - l] = s[i];
        for (int i = l; i <= r; i++)
            s[i] = s1[(i - l - k + le) % le];
    }
    cout << s;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <climits>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define for1(i, n) for (int i = 1; i <= (int)n; i++)
#define forq(i, s, t) for (int i = s; i <= t; i++)
#define ford(i, s, t) for (int i = s; i >= t; i--)
#define mk make_pair
#define inb push_back
#define outb pop_back
#define ump unordered_map
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define randint(x,y)
#define randlong(x, y)
#define TASK ""

const double eps = 1e-15;
const double pi = acos(-1.0);

const int MAXN = (int)1e5 + 7;
const int INF = (ll)2e9;
const ll LINF = (ll)8e18;
const int MOD = (ll)1e9 + 7;

void gen();
int solve();

int main()
{
#ifdef _DEBUG
    gen();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("test.txt", "w", stderr);
    double tstart = TIME;
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
#ifdef _DEBUG
    double tend = TIME;
    cerr << tend - tstart << " s.\n";
#endif
    return 0;
}

void gen()
{
    freopen("input.txt", "a+", stdout);
    srand(time(0));
    return;
}

int solve()
{
    string s;
    cin >> s;
    char s1[MAXN];
    memset(s1, '0', MAXN);
    int m;
    cin >> m;
    while (m--)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        k = k % s.size();
        int le = r - l + 1;
        for (int i = l; i <= r; i++)
            s1[i - l] = s[i];
        for (int i = l; i <= r; i++)
            s[i] = s1[(i - l - k + le) % le];
    }
    cout << s;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <climits>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define for1(i, n) for (int i = 1; i <= (int)n; i++)
#define forq(i, s, t) for (int i = s; i <= t; i++)
#define ford(i, s, t) for (int i = s; i >= t; i--)
#define mk make_pair
#define inb push_back
#define outb pop_back
#define ump unordered_map
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define randint(x,y)
#define randlong(x, y)
#define TASK ""

const double eps = 1e-15;
const double pi = acos(-1.0);

const int MAXN = (int)1e5 + 7;
const int INF = (ll)2e9;
const ll LINF = (ll)8e18;
const int MOD = (ll)1e9 + 7;

void gen();
int solve();

int main()
{
#ifdef _DEBUG
    gen();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("test.txt", "w", stderr);
    double tstart = TIME;
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
#ifdef _DEBUG
    double tend = TIME;
    cerr << tend - tstart << " s.\n";
#endif
    return 0;
}

void gen()
{
    freopen("input.txt", "a+", stdout);
    srand(time(0));
    return;
}

int solve()
{
    string s;
    cin >> s;
    string cur;
    forn(i, s.size() + 3)
        cur.push_back('a');
    int m;
    cin >> m;
    while (m--)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        k = k % s.size();
        int le = r - l + 1;
        for (int i = l; i <= r; i++)
            cur[i - l] = s[i];
        for (int i = l; i <= r; i++)
            s[i] = cur[(i - l - k + le) % le];
    }
    cout << s;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <climits>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define for1(i, n) for (int i = 1; i <= (int)n; i++)
#define forq(i, s, t) for (int i = s; i <= t; i++)
#define ford(i, s, t) for (int i = s; i >= t; i--)
#define mk make_pair
#define inb push_back
#define outb pop_back
#define ump unordered_map
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define randint(x,y)
#define randlong(x, y)
#define TASK ""

const double eps = 1e-15;
const double pi = acos(-1.0);

const int MAXN = (int)1e5 + 7;
const int INF = (ll)2e9;
const ll LINF = (ll)8e18;
const int MOD = (ll)1e9 + 7;

void gen();
int solve();

int main()
{
#ifdef _DEBUG
	gen();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("test.txt", "w", stderr);
	double tstart = TIME;
#else
	//freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
	//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
	solve();
#ifdef _DEBUG
	double tend = TIME;
	cerr << tend - tstart << " s.\n";
#endif
	return 0;
}

void gen()
{
	freopen("input.txt", "a+", stdout);
	srand(time(0));
	return;
}

int solve()
{
	string s;
	cin >> s;
	string cur;
	forn(i, s.size() + 3)
		cur.push_back('a');
	int m;
	cin >> m;
	while (m--)
	{
		int l, r, k;
		cin >> l >> r >> k;
		l--;
		r--;
		k %= s.size();
		int le = r - l + 1;
		for (int i = l; i <= r; i++)
			cur[i - l] = s[i];
		for (int i = l; i <= r; i++)
			s[i] = cur[(i - l - k + le) % le];
	}
	cout << s;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <climits>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define for1(i, n) for (int i = 1; i <= (int)n; i++)
#define forq(i, s, t) for (int i = s; i <= t; i++)
#define ford(i, s, t) for (int i = s; i >= t; i--)
#define mk make_pair
#define inb push_back
#define outb pop_back
#define ump unordered_map
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define randint(x,y)
#define randlong(x, y)
#define TASK ""

const double eps = 1e-15;
const double pi = acos(-1.0);

const int MAXN = (int)1e5 + 7;
const int INF = (ll)2e9;
const ll LINF = (ll)8e18;
const int MOD = (ll)1e9 + 7;

void gen();
int solve();

int main()
{
#ifdef _DEBUG
	gen();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("test.txt", "w", stderr);
	double tstart = TIME;
#else
	//freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
	//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
	solve();
#ifdef _DEBUG
	double tend = TIME;
	cerr << tend - tstart << " s.\n";
#endif
	return 0;
}

void gen()
{
	freopen("input.txt", "a+", stdout);
	srand(time(0));
	return;
}

int solve()
{
	string s;
	cin >> s;
	string cur;
	forn(i, s.size() + 3)
		cur.push_back('a');
	int m;
	cin >> m;
	while (m--)
	{
		int l, r, k;
		cin >> l >> r >> k;
		l--;
		r--;
		int le = r - l + 1;
		for (int i = l; i <= r; i++)
			cur[i - l] = s[i];
		for (int i = l; i <= r; i++)
			s[i] = cur[(i - l - k + le) % le];
	}
	cout << s;
	return 0;
}


#include <iostream>
#include <string>

void taskA() {

	int t = 0;
	std::cin >> t;

	for (int i = 0; i < t; ++i) {

		int n = 0;
		std::cin >> n;

		long long ans = ((long long)n * (n + 1) / 2);

		long long d = 1;

		while (d <= n) {

			ans -= 2 * d;
			d *= 2;

		}

		std::cout << ans << std::endl;

	}

}

void taskB() {

	std::string s = "";
	std::cin >> s;

	int m = 0;
	std::cin >> m;

	for (int i = 0; i < m; ++i) {

		int l = 0, r = 0, k = 0;

		std::cin >> l >> r >> k;
		l--; r--;

		int len = r - l + 1;

		int real_k = k % len;

		std::string new_s = s;

		for (int j = l; j <= r; ++j) {
			new_s[j] = s[l + (j - l - real_k + len) % len];
		}

		s = new_s;

	}

	std::cout << s << std::endl;

}

int main() {

	taskB();

	return 0;
}


#include <iostream>
#include <string>

void taskA() {

	int t = 0;
	std::cin >> t;

	for (int i = 0; i < t; ++i) {

		int n = 0;
		std::cin >> n;

		long long ans = ((long long)n * (n + 1) / 2);

		long long d = 1;

		while (d <= n) {

			ans -= 2 * d;
			d *= 2;

		}

		std::cout << ans << std::endl;

	}

}

void taskB() {

	std::string s = "";
	std::cin >> s;

	int m = 0;
	std::cin >> m;

	for (int i = 0; i < m; ++i) {

		int l = 0, r = 0, k = 0;

		std::cin >> l >> r >> k;
		l--; r--;

		int real_k = k % (r - l + 1);

		for (int count = 0; count < real_k; ++count) {

			char last_char = s[r];

			for (int j = l; j <= r; ++j) {

				char tmp = s[j];
				s[j] = last_char;
				last_char = tmp;

			}

		}

	}

	std::cout << s << std::endl;

}

int main() {

	taskB();

	return 0;
}


#include <bits/stdc++.h>
#define nmax 300005
using namespace std;
int n,k,a[nmax],b[nmax],dem(0);
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++)
        cin >> a[i];
    for(int i=2;i<=n;i++)
    {
        b[i-1]=a[i]-a[i-1];
    }
    dem=a[n]-a[1];
    sort(b+1,b+n);
    for(int i=1;i<k;i++)
        dem-=b[n-i];
    cout << dem;
    return 0;
}


#include <bits/stdc++.h>
#define nmax 300005
using namespace std;
int n,k,a[nmax],dd[nmax],m,sum(0);
struct hd
{
    int d,c,trc,sau;
} b[nmax];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    scanf("%d",&n);
    scanf("%d",&k);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        b[i].d=a[i];
        b[i].c=a[i];
        b[i].trc=i-1;
        b[i].sau=i+1;
    }
    memset(dd,0,sizeof(dd));
    m=n;
    while(m>k)
    {
        m--;
        int minn(INT_MAX),id1(0),id2(0);
        for(int i=1; i<=n; i++)
        {
            if(dd[i]==0)
            {
                int j=b[i].trc;
                //cout << i << " " << j << " " << b[i].c-b[j].d-(b[i].c-b[i].d)-(b[j].c-b[j].d)  << endl;
                if(j!=0)
                {   //cout << i << " " << j << " " << b[i].c-b[j].d-(b[i].c-b[i].d)-(b[j].c-b[j].d)  << endl;
                    if(sum+b[i].c-b[j].d-(b[i].c-b[i].d)-(b[j].c-b[j].d)<minn)
                    {
                        minn=sum+b[i].c-b[j].d-(b[i].c-b[i].d)-(b[j].c-b[j].d);
                        id1=i;
                        id2=j;
                    }
                }
            }
        }
        sum=sum+b[id1].c-b[id2].d-(b[id1].c-b[id1].d)-(b[id2].c-b[id2].d);
        dd[id2]=1;
        b[id1].trc=b[id2].trc;
        b[id1].d=b[id2].d;
    }
    printf("%d",sum);
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;
int a[N];
vi lst;

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0, res = inf;;
    rep(i, 1, n){
        cin >> a[i];
    }
    int ind = 1;
    while(ind <= n){
        while(ind <= n&& a[ind] == a[ind + 1]){
            ind++;
        }
        lst.pb(a[ind]);
        if(ind <= n)
            ind++;
    }
    if((int)lst.size() <= k){
        cout << 0;
    }else{
        int dif = (int)lst.size() - k;
        rep(i, 0, (int)lst.size() - 1 - dif){
            res = min(res, lst[i + dif] - lst[i]);
        }
        cout << res;
    }
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;
int a[N];

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0;
    rep(i, 1, n){
        cin >> a[i];
    }
    a[0] = a[1];
    int ind = n;
    while(ind > 0 && k > 1){
        while(ind > 0 && a[ind] == a[ind - 1]){
            ind--;
        }
        if(ind > 0)
            ind--;
        k--;
    }
    //debug(ind);
    cout << a[ind] - a[1];
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0;
    rep(i, 1, n){
        int x; cin >> x;
        if(i == 1) minN = x;
        if(i + k - 1 == n){
            maxN = x;
        }
    }
    cout << maxN - minN;
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;
int a[N];

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0;
    rep(i, 1, n){
        cin >> a[i];
    }
    int ind = n;
    while(ind > 0 && k > 1){
        while(ind > 0 && a[ind] == a[ind - 1]){
            ind--;
        }
        ind--;
        k--;
    }
    if(ind == 0){
        cout << 0;
        return 0;
    }
    cout << a[ind] - a[1];
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;
int a[N];

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0, res = inf;;
    rep(i, 1, n){
        cin >> a[i];
    }
    sort(a, a + n + 1);
    int ind = n, iniK = k;
    while(ind > 0 && k > 1){
        while(ind > 0 && a[ind] == a[ind - 1]){
            ind--;
        }
        if(ind > 0)
            ind--;
        k--;
    }
    a[0] = a[1];
    //debug(ind);
    res = min(res, a[ind] - a[1]);
    ind = 1;
    k = iniK;
    while(ind <= n && k > 1){
        while(ind <= n && a[ind] == a[ind + 1]){
            ind++;
        }
        if(ind <= n)
            ind++;
        k--;
    }
    res = min(res, a[n] - a[ind]);
    cout << res;
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;
int a[N];
vi lst;

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0, res = 0;
    rep(i, 1, n){
        cin >> a[i];
    }
    int ind = 1;
    while(ind <= n){
        while(ind <= n && a[ind] == a[ind + 1]){
            ind++;
        }
        lst.pb(a[ind]);
        if(ind <= n)
            ind++;
    }
    int m = (int)lst.size();
    if(m <= k){
        cout << 0;
    }else{
        int dif = m - k;
        vi b;
        rep(i, 0, m - 2){
            b.pb(lst[i + 1] - lst[i]);
        }
        sort(b.begin(), b.end());
        rep(i, 0, dif - 1){
            res += b[i];
        }
        cout << res;
    }
    return 0;
}


//https://codeforces.com/contest/1197/problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 300005;
int a[N];

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k; cin >> n >> k;
    int maxN = 0, minN = 0, res = inf;;
    rep(i, 1, n){
        cin >> a[i];
    }
    int ind = n, iniK = k;
    while(ind > 0 && k > 1){
        while(ind > 0 && a[ind] == a[ind - 1]){
            ind--;
        }
        if(ind > 0)
            ind--;
        k--;
    }
    a[0] = a[1];
    //debug(ind);
    res = min(res, a[ind] - a[1]);
    ind = 0;
    k = iniK;
    while(ind <= n && k > 1){
        while(ind <= n && a[ind] == a[ind + 1]){
            ind++;
        }
        if(ind <= n)
            ind++;
        k--;
    }
    a[n + 1] = a[n];
    res = min(res, a[n] - a[ind]);
    cout << res;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll i,j;
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<pair<ll,ll>> v;
    for(i=0,j=0;i<n;i++)
    {
        while(i+1<n && a[i]==a[i+1])
            i++;
        v.pb({j,i});
        j=i+1;
    }
    if(v.size()<=k)
        cout<<"0";//" "<<v.size();
    else
    {
        // for(i=0;i<v.size();i++)
        // {
            // cout<<v[i].fi<<" "<<v[i].se<<"\n";
        // }
        ll ans=INT_MAX;
        vector<ll> p;
        for(i=0;i<v.size()-1;i++){
            // cout<<a[v[i].fi]<<" "<<a[v[i+1].se]<<"\n";
            p.pb(abs(a[v[i].fi]-a[v[i+1].se]));
            // cout<<p[i]<<"\n";
        }
        ll pre[p.size()];
        pre[0]=p[0];
        for(i=1;i<p.size();i++)
            pre[i]=p[i]+pre[i-1];
        ll t=p.size()-k;
        // cout<<t<<"\n";
        if(t==0)
        {
            for(i=0;i<p.size();i++)
                ans=min(ans,p[i]);
            cout<<ans;
            return;
        }
        for(i=0;i+t<p.size();i++)
        {
            if(i==0)
            ans=min(ans,pre[t+i]);
            else
                ans=min(ans,pre[t+i]-pre[i-1]);
            // cout<<pre[i]<<" ";
        }
        cout<<ans;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t tStart = clock();
    ll t,k;
    // cin>>t;
    // while(t--)
        solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll i,j;
    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(),greater<ll>());
    ll ans=a[n-1]-a[0];
    for(i=0;i<k-1;i++)
        ans-=v[i];
    cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t tStart = clock();
    ll t,k;
    // cin>>t;
    // while(t--)
        solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll i,j;
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<pair<ll,ll>> v;
    for(i=0,j=0;i<n;i++)
    {
        while(i+1<n && a[i]==a[i+1])
            i++;
        v.pb({j,i});
        j=i+1;
    }
    if(v.size()<=k)
        cout<<"0";
    else
    {
        ll m=INT_MAX;
        for(i=0;i<n;i++)
        {
            if(n-k+i<n)
            m=min(m,a[n-k+i]-a[i]);
        }
        cout<<m;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t tStart = clock();
    ll t,k;
    // cin>>t;
    // while(t--)
        solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll i,j;
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<pair<ll,ll>> v;
    for(i=0,j=0;i<n;i++)
    {
        while(i+1<n && a[i]==a[i+1])
            i++;
        v.pb({j,i});
        j=i+1;
    }
    if(v.size()<=k)
        cout<<"0";//" "<<v.size();
    else
    {
        // for(i=0;i<v.size();i++)
        // {
            // cout<<v[i].fi<<" "<<v[i].se<<"\n";
        // }
        ll ans=INT_MAX;
        vector<ll> p;
        for(i=0;i<v.size()-1;i++){
            // cout<<a[v[i].fi]<<" "<<a[v[i+1].se]<<"\n";
            p.pb(abs(a[v[i].fi]-a[v[i+1].se]));
            // cout<<p[i]<<"\n";
        }
        ll pre[p.size()];
        pre[0]=p[0];
        for(i=1;i<p.size();i++)
            pre[i]=p[i]+pre[i-1];
        ll t=p.size()-k;
        // cout<<t<<"\n";
        if(t==0)
        {
            for(i=0;i<p.size();i++)
                ans=min(ans,pre[i]);
            cout<<ans;
            return;
        }
        for(i=0;i+t<p.size();i++)
        {
            if(i==0)
            ans=min(ans,pre[t+i]);
            else
                ans=min(ans,pre[t+i]-pre[i-1]);
            // cout<<pre[i]<<" ";
        }
        cout<<ans;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t tStart = clock();
    ll t,k;
    // cin>>t;
    // while(t--)
        solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll i,j;
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<pair<ll,ll>> v;
    for(i=0,j=0;i<n;i++)
    {
        while(i+1<n && a[i]==a[i+1])
            i++;
        v.pb({j,i});
        j=i+1;
    }
    if(v.size()<=k)
        cout<<"0";//" "<<v.size();
    else
    {
        // for(i=0;i<v.size();i++)
        // {
            // cout<<v[i].fi<<" "<<v[i].se<<"\n";
        // }
        ll ans=INT_MAX;
        vector<ll> p;
        for(i=0;i<v.size()-1;i++){
            // cout<<a[v[i].fi]<<" "<<a[v[i+1].se]<<"\n";
            p.pb(abs(a[v[i].fi]-a[v[i+1].se]));
            // cout<<p[i]<<"\n";
        }
        ll pre[p.size()];
        pre[0]=p[0];
        for(i=1;i<p.size();i++)
            pre[i]=p[i]+pre[i-1];
        ll t=p.size()-k;
        // cout<<t<<"\n";
        if(t==0)
        {
            for(i=0;i<p.size();i++)
                ans=min(ans,p[i]);
            cout<<ans;
            return;
        }
        for(i=0;i+t<p.size();i++)
        {
            if(i==0)
            ans=min(ans,pre[t+i]);
            else
                ans=min(ans,pre[t+i]-pre[i-1]);
            // cout<<pre[i]<<" ";
        }
        cout<<pre[t];
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t tStart = clock();
    ll t,k;
    // cin>>t;
    // while(t--)
        solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll i,j;
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<pair<ll,ll>> v;
    for(i=0,j=0;i<n;i++)
    {
        while(i+1<n && a[i]==a[i+1])
            i++;
        v.pb({j,i});
        j=i+1;
    }
    if(v.size()<=k)
        cout<<"0";//" "<<v.size();
    else
    {
        // for(i=0;i<v.size();i++)
        // {
            // cout<<v[i].fi<<" "<<v[i].se<<"\n";
        // }
        ll ans=INT_MAX;
        vector<ll> p;
        for(i=0;i<v.size()-1;i++){
            // cout<<a[v[i].fi]<<" "<<a[v[i+1].se]<<"\n";
            p.pb(abs(a[v[i].fi]-a[v[i+1].se]));
            // cout<<p[i]<<"\n";
        }
        ll pre[p.size()];
        pre[0]=p[0];
        for(i=1;i<p.size();i++)
            pre[i]=p[i]+pre[i-1];
        ll t=p.size()-k;
        // cout<<t<<"\n";
        if(t==0)
        {
            for(i=0;i<p.size();i++)
                ans=min(ans,pre[i]);
            cout<<ans;
            return;
        }
        for(i=0;i+t<p.size();i++)
        {
            if(i==0)
            ans=min(ans,pre[t+i]);
            else
                ans=min(ans,pre[t+i]-pre[i-1]);
            // cout<<pre[i]<<" ";
        }
        cout<<pre[t];
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t tStart = clock();
    ll t,k;
    // cin>>t;
    // while(t--)
        solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define MAX 111111
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n,k,i,a[MAX],sum=0;
        vector<int> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define MAX 1111111
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = int(3e5) + 99;

int n, k;
int a[N];

int main(){
	cin >> n >> k;
	for(int i = 0; i < n; ++i)
		cin >> a[i];

	vector <int> v;
	for(int i = 1; i < n; ++i) v.push_back(a[i - 1] - a[i]);

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

	int res = a[n - 1] - a[0];
	for(int i = 0; i < k - 1; ++i) res += v[i];

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


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 1111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++)
            cin>>a[i];
        for (i=0;i<n-1;i++)
            v.push_back(a[i]-a[i+1]);
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
/*bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}*/
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        ll n,k,i,a[MAX],sum=0;
        vector<ll> v;
        cin>>n>>k;
        for (i=0;i<n;i++){
            cin>>a[i];
            if (i)
                v.push_back(a[i-1]-a[i]);
        }
        sort(v.begin(),v.end());
        sum=a[n-1]-a[0];
        for (i=0;i<k-1;i++)
            sum+=v[i];
        cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define MAX 111111
#define ll long long int
#define ld long double
#define inf ((ll)INT_MAX)*1000
using namespace std;
bool s[MAX];
ll f[MAX];
ll fibo[MAX];
ll fibonacci(ll x){
    fibo[1]=fibo[2]=1;
    if (x<MAX && !fibo[x])
        return fibo[x];
    if (x<MAX)
        return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
    return fibo[x]=(fibonacci(x-1)+fibonacci(x-2))%mod;
}
ll mul(ll a,ll b,ll m){
    ll result=0;
    a%=m;
    while(b){
        if (b&1)
            result=(result+a)%m;
        a=(2*a)%m;
        b>>=1;
    }
    return result;
}
ll power(ll b,ll e,ll m){
    ll result=1;
    b%=m;
    while(e){
        if (e&1)
            result=mul(result,b,m);
        e>>=1;
        b=mul(b,b,m);
    }
    return result;
}
bool func1(pair<ll,ll> x,pair<ll,ll> y){
    if (x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
bool func2(pair<ll,ll> x,pair<ll,ll> y){
    if (x.second==y.second)
        return x.first<y.first;
    return x.second<y.second;
}
bool dfunc(ll a,ll b){
    return a>b;
}
ll fact(ll x){
    if (x<=1)
        return f[x]=1;
    if (f[x])
        return f[x];
    return x*fact(x-1);
}
void seive(){
    for (ll i=2;i<MAX;i++)
        if (!s[i])
            for (ll j=i*i;j<MAX;j+=i)
                s[j]=true;
}
vector<vector<ll>> adj(MAX);
bool visited[MAX];
queue<ll> q;
vector<ll> side(MAX,-1);
ll cover1,cover2;
bool isbi=true;
void dfs(ll n){
    visited[n]=true;
    for (ll i:adj[n])
        if (!visited[i])
            dfs(i);
}
void bibfs(ll n){
    ll s;
    for (s=1;s<=n;s++)
        if (side[s]==-1){
            q.push(s);
            side[s]=0;
            cover1++;
            while(!q.empty()){
                ll temp=q.front();
                q.pop();
                for (ll j:adj[temp])
                    if (side[j]==-1){
                        q.push(j);
                        side[j]=side[temp]^1;
                        if (!side[j])
                            cover1++;
                        else
                            cover2++;
                    }
                    else
                        isbi&=(side[j]!=side[temp]);
            }
        }
}
void bfs(ll n){
    q.push(n);
    while(!q.empty()){
        ll temp=q.front();
        q.pop();
        visited[temp]=true;
        for (ll j:adj[temp])
            if (!visited[j])
                q.push(j);
    }
}
vector<vector<pair<ll,ll>>> adj1(MAX);
void dk(ll n,ll s,vector<ll> &d,vector<ll> &p){
    ll i,j,v;
    d[s]=0;
    vector<bool> u(n+5,false);
    for (i=1;i<=n;i++){
        v=-1;
        for (j=1;j<=n;j++)
            if (!u[j] && (v==-1 || d[j]<d[v]))
                v=j;
        u[v]=true;
        if (d[v]==((ll)INT_MAX)*1000)
            break;
        for (pair<ll,ll> temp:adj1[v])
            if (d[v]+temp.second<d[temp.first]){
                d[temp.first]=d[v]+temp.second;
                p[temp.first]=v;
            }
    }
}
ll sakamoto(ll d,ll m,ll y){
    ll t[]={0,3,2,5,0,3,5,1,4,6,2,4};
    if (m<3)
        y-=1;
    return ((y+y/4-y/100+y/400+t[m-1]+d)%7);
}
ll seg1[MAX];
vector<ll> a;
void build(ll left,ll right,ll index){
    if (left==right){
        seg1[index]=a[left];
        return;
    }
    ll mid=(left+right)/2;
    build(left,mid,2*index);
    build(mid+1,right,2*index+1);
    seg1[index]=seg1[2*index]+seg1[2*index+1];
}
ll query(ll left,ll right,ll lindex,ll rindex,ll index){
    if (right<lindex || rindex<left)
        return 0;
    if (left<=lindex && right>=rindex)
        return seg1[index];
    return query(left,right,lindex,(lindex+rindex)/2,2*index)+query(left,right,(lindex+rindex)/2+1,rindex,2*index+1);
}
bool check(ll n,ll a,ll d,ll s){
	ll x=power(a,d,n);
	if (x==1 || x==n-1)
		return false;
	for (ll i=1;i<s;i++){
		x=mul(x,x,n);
		if (x==n-1)
			return false;
	}
	return true;
}
bool miller(ll n,ll iter){
    srand(time(0));
	if (n<4)
		return n==2 || n==3;
	ll d=n-1;
	ll s=0;
	while(!(d&1)){
		d>>=1;
		s++;
	}
	for (ll i=1;i<=iter;i++){
        ll a=2+rand()%(n-3);
		if (check(n,a,d,s))
			return false;
	}
	return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,k,i,a[MAX];
        cin>>n>>k;
        for (i=0;i<n;i++)
            cin>>a[i];
        cout<<(a[n-k]-a[0])<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
bool SortPair(pair<int, int> &p1, pair<int, int> &p2) {
	return p1.first > p2.first;
}
int n, k;
int main()
{
	long long num = 0, ans = 0, prom = 0;
	scanf("%d%d", &n, &k);
	vector<int> vec(n), vec1(k-1), vec2;
	vector<pair<int, int>>pr(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
		if (i == 0) {
			num = vec[i];
			pr[i].first = 1;
			vec2.push_back(pr[i].second);
			continue;
		}
		pr[i].first = vec[i] - num, pr[i].second = i;
		vec2.push_back(pr[i].first);
		num = vec[i];
	}
	if (k == 1) {
		cout << vec[n - 1] - vec[0];
		return 0;
	}
	sort(pr.begin(), pr.end(), SortPair);
	/*
	 for (int i = 0; i < n; i++) {
		cout << pr[i].second << ' ';
	}
	 */
	for (int i = 0; i < k - 1; i++) {
		vec1[i] = pr[i].second;
	}
	sort(vec1.begin(), vec1.end());
	num = 0;
	for (int i = 0; i < n; i++) {
		if (i == vec1[num]) {
			ans += prom;
			prom = 0;
			num++;
			if (num == k-1) break;
			continue;
		}
		prom += vec2[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
bool SortPair(pair<int, int> &p1, pair<int, int> &p2) {
	return p1.first > p2.first;
}
int n, k;
int main()
{
	int num = 0, ans = 0, prom = 0;
	scanf("%d%d", &n, &k);
	vector<int> vec(n), vec1(k-1), vec2;
	vector<pair<int, int>>pr(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
		if (i == 0) {
			num = vec[i];
			pr[i].first = 1;
			vec2.push_back(pr[i].second);
			continue;
		}
		pr[i].first = vec[i] - num, pr[i].second = i;
		vec2.push_back(pr[i].first);
		num = vec[i];
	}
	if (k == 1) {
		cout << vec[n - 1] - vec[0];
		return 0;
	}
	sort(pr.begin(), pr.end(), SortPair);
	/*
	 for (int i = 0; i < n; i++) {
		cout << pr[i].second << ' ';
	}
	 */
	for (int i = 0; i < k - 1; i++) {
		vec1[i] = pr[i].second;
	}
	sort(vec1.begin(), vec1.end());
	num = 0;
	for (int i = 0; i < n; i++) {
		if (i == vec1[num]) {
			ans += prom;
			prom = 0;
			num++;
			continue;
		}
		prom += vec2[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
bool SortPair(pair<int, int> &p1, pair<int, int> &p2) {
	return p1.first > p2.first;
}
int n, k;
int main()
{
	int num = 0, ans = 0, prom = 0;
	scanf_s("%d%d", &n, &k);
	vector<int> vec(n), vec1(k-1), vec2;
	vector<pair<int, int>>pr(n);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &vec[i]);
		if (i == 0) {
			num = vec[i];
			pr[i].first = 1;
			vec2.push_back(pr[i].second);
			continue;
		}
		pr[i].first = vec[i] - num, pr[i].second = i;
		vec2.push_back(pr[i].first);
		num = vec[i];
	}
	if (k == 1) {
		cout << vec[n - 1] - vec[0];
		return 0;
	}
	sort(pr.begin(), pr.end(), SortPair);
	/*
	 for (int i = 0; i < n; i++) {
		cout << pr[i].second << ' ';
	}
	 */
	for (int i = 0; i < k - 1; i++) {
		vec1[i] = pr[i].second;
	}
	sort(vec1.begin(), vec1.end());
	num = 0;
	for (int i = 0; i < n; i++) {
		if (i == vec1[num]) {
			ans += prom;
			prom = 0;
			num++;
			if (num == k-1) break;
			continue;
		}
		prom += vec2[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
int main()
{
	long long n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> razn(n - 1);
	for (ll i = 1; i < n; ++i) {
		razn[i - 1] = a[i] - a[i - 1];
	}
	sort(razn.begin(), razn.end());
	long long ans = 0;
	for (long long i = 0; i < n - k; ++i) {
		ans += razn[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
int main()
{
	long long n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> razn(n - 1);
	for (long long i = 1; i < n; ++i) {
		razn[i - 1] = a[i] - a[i - 1];
	}
	sort(razn.begin(), razn.end());
	long long ans = 0;
	for (long long i = 0; i < n - k; ++i) {
		ans += razn[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
bool SortPair(pair<int, int> &p1, pair<int, int> &p2) {
	return p1.first > p2.first;
}
int n, k;
int main()
{
	int num = 0, ans = 0, prom = 0;
	scanf("%d%d", &n, &k);
	vector<int> vec(n), vec1(k-1), vec2;
	vector<pair<int, int>>pr(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
		if (i == 0) {
			num = vec[i];
			pr[i].first = 1;
			vec2.push_back(pr[i].second);
			continue;
		}
		pr[i].first = vec[i] - num, pr[i].second = i;
		vec2.push_back(pr[i].first);
		num = vec[i];
	}
	if (k == 1) {
		cout << vec[n - 1] - vec[0];
		return 0;
	}
	sort(pr.begin(), pr.end(), SortPair);
	/*
	 for (int i = 0; i < n; i++) {
		cout << pr[i].second << ' ';
	}
	 */
	for (int i = 0; i < k - 1; i++) {
		vec1[i] = pr[i].second;
	}
	sort(vec1.begin(), vec1.end());
	num = 0;
	for (int i = 0; i < n; i++) {
		if (i == vec1[num]) {
			ans += prom;
			prom = 0;
			num++;
			if (num == k-1) break;
			continue;
		}
		prom += vec2[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
bool SortPair(pair<int, int> &p1, pair<int, int> &p2) {
	return p1.first > p2.first;
}
int n, k;
int main()
{
	int num = 0, ans = 0, prom = 0;
	scanf("%d%d", &n, &k);
	vector<int> vec(n), vec1(k-1), vec2;
	vector<pair<int, int>>pr(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
		if (i == 0) {
			num = vec[i];
			pr[i].first = 1;
			vec2.push_back(pr[i].second);
			continue;
		}
		pr[i].first = vec[i] - num, pr[i].second = i;
		vec2.push_back(pr[i].first);
		num = vec[i];
	}
	if (k == 1) {
		cout << vec[n - 1] - vec[0];
		return 0;
	}
	sort(pr.begin(), pr.end(), SortPair);
	/*
	 for (int i = 0; i < n; i++) {
		cout << pr[i].second << ' ';
	}
	 */
	for (int i = 0; i < k - 1; i++) {
		vec1[i] = pr[i].second;
	}
	sort(vec1.begin(), vec1.end());
	num = 0;
	for (int i = 0; i < n; i++) {
		if (i == vec1[num] && num + 1 < vec1.size()) {
			ans += prom;
			prom = 0;
			num++;
			continue;
		}
		prom += vec2[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <deque>
#include <set>
using namespace std;
bool SortPair(pair<int, int> &p1, pair<int, int> &p2) {
	return p1.first > p2.first;
}
int n, k;
int main()
{
	int num = 0, ans = 0, prom = 0;
	scanf_s("%d%d", &n, &k);
	vector<int> vec(n), vec1(k-1), vec2;
	vector<pair<int, int>>pr(n);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &vec[i]);
		if (i == 0) {
			num = vec[i];
			pr[i].first = 1;
			vec2.push_back(pr[i].second);
			continue;
		}
		pr[i].first = vec[i] - num, pr[i].second = i;
		vec2.push_back(pr[i].first);
		num = vec[i];
	}
	if (k == 1) {
		cout << vec[n - 1] - vec[0];
		return 0;
	}
	sort(pr.begin(), pr.end(), SortPair);
	/*
	 for (int i = 0; i < n; i++) {
		cout << pr[i].second << ' ';
	}
	 */
	for (int i = 0; i < k - 1; i++) {
		vec1[i] = pr[i].second;
	}
	sort(vec1.begin(), vec1.end());
	num = 0;
	for (int i = 0; i < n; i++) {
		if (i == vec1[num]) {
			ans += prom;
			prom = 0;
			num++;
			continue;
		}
		prom += vec2[i];
	}
	cout << ans;
}