#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,i,cnt=0;           cin>>n>>k;
    vector<long long int>v(n);
    for(i=0;i<n;i++)                     cin>>v[i];
    cnt=v[n-1]-v[0];
    for(i=n-1;i>0;i--)                   v[i]-=v[i-1];
    sort(v.begin()+1,v.begin()+n);
    for(i=1;i<k;i++)                     cnt-=v[n-i];
    cout<<cnt;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,cnt=0;        cin>>n>>k;
    vector<long long int>v(n);
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[b-1] && v[b-1]!=v[b-2] && b!=k){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cout<<cnt+v[b]-v[0];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,c,cnt=0,cn=0; cin>>n>>k;
    vector<long long int>v(n);          c=k-1;
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[0] && v[b-1]!=v[b-2] && b!=k-1){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cnt+=v[b]-v[0];                     a=n-1;b=n-1;
    while(c!=0){
        while(v[a]-v[b]<=v[b]-v[0] && v[0]!=v[b-2] && b!=c-1){
            b--;
        }
        cn+=v[a]-v[b+1];
        a=b;                            c--;
    }
    cn+=v[b]-v[0];
    cout<<min(cnt,cn);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,cnt=0;        cin>>n>>k;
    vector<long long int>v(n);
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[b-1] && b!=k-1){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cout<<cnt+v[b]-v[0];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,c,cnt=0,cn=0; cin>>n>>k;
    vector<long long int>v(n);          c=k-1;
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[0] && v[b-1]!=v[b-2] && b!=k-1){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cnt+=v[b]-v[0];                     a=n-1;b=n-1;
    while(c!=0){
        while(v[a]-v[b]<=v[b]-v[0] && v[b-1]!=v[b-2] && b!=c-1){
            b--;
        }
        cn+=v[a]-v[b+1];
        a=b;                            c--;
    }
    cn+=v[b]-v[0];
    cout<<min(cnt,cn);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,cnt=0;        cin>>n>>k;
    vector<long long int>v(n);
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[b-1] && b!=k){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cout<<cnt+v[b]-v[0];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,cnt=0;        cin>>n>>k;
    vector<long long int>v(n);
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<v[b]-v[b-1] && b!=k-1){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cout<<cnt+v[b]-v[0];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,cnt=0;        cin>>n>>k;
    vector<long long int>v(n);
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[b-1] && v[b-1]!=v[b-2] && b!=k-1){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cout<<cnt+v[b]-v[0];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long int n,k,a,b,c,cnt=0,cn=0; cin>>n>>k;
    vector<long long int>v(n);          c=k-1;
    for(long long int i=0;i<n;i++)      cin>>v[i];
    if(k==1){
        cout<<v[n-1]-v[0];              return 0;
    }
    if(k==n){
        cout<<0;                        return 0;
    }a=n-1;b=n-1;k--;
    while(k!=0){
        while(v[a]-v[b]<=v[b]-v[0] && v[b-1]!=v[b-2] && b!=k-1){
            b--;
        }
        cnt+=v[a]-v[b+1];
        a=b;                            k--;
    }
    cnt+=v[b]-v[0];                     a=n-1;b=n-1;
    while(c!=0){
        while(v[a]-v[b]<=v[b]-v[b-1] && v[b-1]!=v[b-2] && b!=c-1){
            b--;
        }
        cn+=v[a]-v[b+1];
        a=b;                            c--;
    }
    cn+=v[b]-v[0];
    cout<<min(cnt,cn);
    return 0;
}


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

using namespace std;

//defines
typedef long long ll;

using namespace std;

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

    int n,k; cin>>n>>k;
    vector<int> arr(n);

    for(int i=0; i<n; i++){
        cin>>arr[i];
    }

    int ans=INT_MAX; int len=n-k+1;
    for(int i=0; i+len<=n; i++){
        ans=min(ans,arr[i+len-1]-arr[i]);
    }

    cout<<ans<<endl;

}


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

using namespace std;

//defines
typedef long long ll;

using namespace std;

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

    int n,k; cin>>n>>k;
    vector<int> arr(n);

    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    vector<int> narr(n-1);
    long long ans=0;

    for(int i=0; i+1<n; i++){
        narr[i]=arr[i+1]-arr[i]; ans+=narr[i];
    }
    sort(narr.begin(),narr.end());

     int len=k-1;
    for(int i=0; i<len; i++) ans-=narr[n-1-i];

    cout<<ans<<endl;

}


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

using namespace std;

//defines
typedef long long ll;

using namespace std;

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

    int n,k; cin>>n>>k;
    vector<int> arr(n);

    for(int i=0; i<n; i++){
        cin>>arr[i];
    }

    cout<<min(arr[n-k]-arr[0],arr[n-1]-arr[k-1])<<endl;

}


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

using namespace std;

//defines
typedef long long ll;

using namespace std;

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

    int n,k; cin>>n>>k;
    vector<int> arr(n);

    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    vector<int> narr(n-1);
    long long ans=0;

    for(int i=0; i+1<n; i++){
        narr[i]=arr[i+1]-arr[i]; ans+=narr[i];
    }
    sort(narr.begin(),narr.end());

     int len=k-1;
    for(int i=0; i<k; i++) ans-=narr[n-1-i];

    cout<<ans<<endl;

}


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

using namespace std;

//defines
typedef long long ll;

using namespace std;

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

    int n,k; cin>>n>>k;
    vector<int> arr(n);

    for(int i=0; i<n; i++){
        cin>>arr[i];
    }

    cout<<arr[n-k]-arr[0]<<endl;

}


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

using namespace std;

//defines
typedef long long ll;

using namespace std;

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

    int n,k; cin>>n>>k;
    vector<int> arr(n);

    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    vector<int> narr(n-1);
    long long ans=0;

    for(int i=0; i+1<n; i++){
        narr[i]=arr[i+1]-arr[i]; ans+=narr[i];
    }
    sort(narr.begin(),narr.end());

     int len=k-1;
    for(int i=0; i<len; i++) ans-=narr[n-2-i];

    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define tc ll t; cin>>t; while(t--)
using namespace std;
int main()
{
    ll n,k; cin>>n>>k;
    ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
    if(n==k)cout<<"0";
    else if(k==1) cout<<a[n-1]-a[0];
    else
    {ll ans1=a[n-k]-a[0];
    ll ans2=a[n-1]-a[k];
    cout<<min(ans1,ans2);}
}


#include<bits/stdc++.h>
#define ll long long
#define tc ll t; cin>>t; while(t--)
using namespace std;
int main()
{
    ll n,k; cin>>n>>k;
    ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
    ll s=0,mn=100000000;
    ll p=n-k+1;
    for(ll i=0;i<=n-p;i++)
    {
        s=a[i+p-1]-a[i];
        cout<<s<<endl;
        mn=min(s,mn);
    }
    cout<<mn;
}


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


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


#include<bits/stdc++.h>
#define ll long long
#define tc ll t; cin>>t; while(t--)
using namespace std;
int main()
{
    ll n,k; cin>>n>>k;
    ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
    ll s=0,mn=100000000;
    ll p=n-k+1;
    for(ll i=0;i<=n-p;i++)
    {
        s=a[i+p-1]-a[i];
        //cout<<s<<endl;
        mn=min(s,mn);
    }
    cout<<mn;
}


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


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	int n, arr[M], mi = 1e9 + 10, k, step;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
	step = n - k;
	for(int j = step; j < n;j++)
	{
		mi = min(arr[j] - arr[j - step], mi);
	}
	printf("%d", mi);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	int n, arr[M], mi = 0, k, step;
	ll res = 0;
	vector<int> v, ans;
	map<int, int> mp;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++)
	{
        scanf("%d", &arr[i]);
        mp[arr[i]]++;
	}
	for(auto it : mp) v.push_back(it.first);
	for(int i = 0; i + 1 < sz(v); i++)
    {
        ans.push_back(v[i + 1] - v[i]);
    }
    sort(all(ans));
    k--;
    for(int i = 0; i + k< sz(ans); i++) res += 1LL * ans[i];

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	int n, arr[M], mi = 1e9 + 10, k, step, f = 0;
	vector<int> v;
	map<int, int> mp;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++)
	{
        scanf("%d", &arr[i]);
        mp[arr[i]]++;
	}
	for(auto it : mp) v.push_back(it.first);
	step = sz(v) - k;
	if(step < 0) step = 0;
	for(int j = step; j < sz(v);j++)
	{
		mi = min(v[j] - v[j - step], mi);
	}
	printf("%d", mi);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	int n, arr[M], mi = 1e9 + 10, k, step;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
	step = n - k;
	for(int i = 0, j = step; i < n - step; i++, j++)
	{
		mi = min(arr[j] - arr[i], mi);
	}
	printf("%d", mi);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	ll n, arr[M], mi = 1e9 + 10, k, step;
	scanf("%lld %lld", &n, &k);
	for(int i = 0; i < n; i++) scanf("%lld", &arr[i]);
	step = n - k;
	for(int i = 0, j = step; i < n - step; i++, j++)
	{
	    if(j >= n) break;
		mi = min(arr[j] - arr[i], mi);
	}
	printf("%lld", mi);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	int n, arr[M], mi = 1e9 + 10, k, step;
	vector<int> v;
	map<int, int> mp;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++)
	{
        scanf("%d", &arr[i]);
        mp[arr[i]]++;
	}
	for(auto it : mp) v.push_back(it.first);
	step = sz(v) - k;
	if(step < 0) step = 0;
	for(int j = step; j < sz(v);j++)
	{
		mi = min(v[j] - v[j - step], mi);
	}
	if(mi == 1e9 + 10) mi = 0;
	printf("%d", mi);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
const int M = (int)3e5 + 10;

int main()
{
	int n, arr[M], mi = 1e9 + 10, k, step, f = 0;
	map<int, int> mp;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++)
	{
        scanf("%d", &arr[i]);
        mp[arr[i]]++;
	}
	for(auto it : mp) f += it.second - 1;
	step = n - k;
	step -= f;
	if(step < 0) step = 0;
	for(int j = step; j < n;j++)
	{
		mi = min(arr[j] - arr[j - step], mi);
	}
	printf("%d", mi);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n, k;
    is >> n >> k;
    int first, prev, next;
    is >> first;
    prev = first;
    vi differences;
    differences.reserve(n - 1);
    rep(_, 0, n - 1) {
        is >> next;
        differences.eb(prev - next);
        prev = next;
    }
    i64 result = prev - first;
    sort(all(differences));
    result += accumulate(differences.begin(), differences.begin() + k - 1, i64(0));
    os << result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15) << fixed;
    Solve(cin, cout);
    return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n, k;
    is >> n >> k;
    int first = 0, prev = 0, next = 0;
    is >> first;
    prev = first;
    vi differences;
    differences.reserve(n - 1);
    rep(_, 0, n - 1) {
        is >> next;
        differences.eb(prev - next);
        prev = next;
    }
    i64 result = next - first;
    sort(all(differences));
    result += accumulate(differences.begin(), differences.begin() + k - 1, i64(0));
    os << result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15) << fixed;
    Solve(cin, cout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n, k;
    is >> n >> k;
    vi input(n);
    is >> input;
    int max_elem = *max_element(all(input) - k + 1);
    int min_elem = *min_element(all(input) - k + 1);
    os << max_elem - min_elem;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15) << fixed;
    Solve(cin, cout);
    return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n, k;
    is >> n >> k;
    int first, prev, next;
    is >> first;
    prev = first;
    vi differences;
    differences.reserve(n - 1);
    rep(_, 0, n - 1) {
        is >> next;
        differences.eb(prev - next);
        prev = next;
    }
    i64 result = next - first;
    sort(all(differences));
    result += accumulate(differences.begin(), differences.begin() + k - 1, i64(0));
    os << result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15) << fixed;
    Solve(cin, cout);
    return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n, k, first, prev, next;
    is >> n >> k >> first;
    prev = first;
    vi differences;
    differences.reserve(n - 1);
    while (--n) {
        is >> next;
        differences.eb(prev - next);
        prev = next;
    }
    sort(all(differences));
    os << accumulate(differences.begin(), differences.begin() + k - 1, i64(0)) + prev - first;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15) << fixed;
    Solve(cin, cout);
    return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n, k;
    is >> n >> k;
    vi input(n);
    is >> input;

    i64 result = input.back() - input.front();
    vi differences;
    differences.reserve(n - 1);
    rep(i, 0, n - 1) {
        differences.eb(input[i] - input[i + 1]);
    }
    sort(all(differences));
    result += accumulate(differences.begin(), differences.begin() + k - 1, i64(0));
    os << result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15) << fixed;
    Solve(cin, cout);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rev(i,a,n) for (int i=a;i>n;i--)
#define repi(it,v) for (auto it=v.begin();it!=v.end();it++)
#define revi(it,v) for (auto it=v.rbegin();it!=v.rend();it++)
//gen
#define pii pair<int,int>
#define fr first
#define sc second
#define mpr make_pair
#define all(v) v.begin(),v.end()
#define init(a,i) memeset(a,i,sizeof(a))
//vec
#define vi vector <int>
#define vc vector <char>
#define pb push_back
//set
#define si set <int>
#define in insert

#define endl "\n"
//var
#define L 1000000007
#define mod 100007

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 //type
#define int long long

using namespace std;
signed main()
{
  io;
  int n,k,r;
  cin>>n>>k;
  set <int> s;
  rep(i,0,n)
  {
    cin>>r;
    s.in(r);
  }
  auto it=s.rbegin();
  while(--k) it++;
  cout<<*it-*(s.begin());

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rev(i,a,n) for (int i=a;i>n;i--)
#define repi(it,v) for (auto it=v.begin();it!=v.end();it++)
#define revi(it,v) for (auto it=v.rbegin();it!=v.rend();it++)
//gen
#define pii pair<int,int>
#define fr first
#define sc second
#define mpr make_pair
#define all(v) v.begin(),v.end()
#define init(a,i) memeset(a,i,sizeof(a))
//vec
#define vi vector <int>
#define vc vector <char>
#define pb push_back
//set
#define si set <int>
#define in insert

#define endl "\n"
//var
#define L 1000000007
#define mod 100007

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 //type
#define int long long

using namespace std;
signed main()
{
  io;
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,0,n) cin>>a[i];

  cout<<a[n-k]-a[0];

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rev(i,a,n) for (int i=a;i>n;i--)
#define repi(it,v) for (auto it=v.begin();it!=v.end();it++)
#define revi(it,v) for (auto it=v.rbegin();it!=v.rend();it++)
//gen
#define pii pair<int,int>
#define fr first
#define sc second
#define mpr make_pair
#define all(v) v.begin(),v.end()
#define init(a,i) memeset(a,i,sizeof(a))
//vec
#define vi vector <int>
#define vc vector <char>
#define pb push_back
//set
#define si set <int>
#define in insert

#define endl "\n"
//var
#define L 1000000007
#define mod 100007

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 //type
#define int long long

using namespace std;
signed main()
{
  io;
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,0,n) a[i];
  cout<<a[n-k]-a[0];

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rev(i,a,n) for (int i=a;i>n;i--)
#define repi(it,v) for (auto it=v.begin();it!=v.end();it++)
#define revi(it,v) for (auto it=v.rbegin();it!=v.rend();it++)
//gen
#define pii pair<int,int>
#define fr first
#define sc second
#define mpr make_pair
#define all(v) v.begin(),v.end()
#define init(a,i) memeset(a,i,sizeof(a))
//vec
#define vi vector <int>
#define vc vector <char>
#define pb push_back
//set
#define si set <int>
#define in insert

#define endl "\n"
//var
#define L 1000000007
#define mod 100007

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 //type
#define int long long

using namespace std;
signed main()
{
  io;

    int n,k,sum=0;

    cin>> n >> k;
    int a[n], b[n-1];
    rep(i,0,n) cin>> a[i];
    rep(i,0,n-1) b[i]=a[i+1]-a[i];
    sort(b,b+n-1);

    rep(i,0,n-k) sum+=b[i];
    cout<< sum;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rev(i,a,n) for (int i=a;i>n;i--)
#define repi(it,v) for (auto it=v.begin();it!=v.end();it++)
#define revi(it,v) for (auto it=v.rbegin();it!=v.rend();it++)
//gen
#define pii pair<int,int>
#define fr first
#define sc second
#define mpr make_pair
#define all(v) v.begin(),v.end()
#define init(a,i) memeset(a,i,sizeof(a))
//vec
#define vi vector <int>
#define vc vector <char>
#define pb push_back
//set
#define si set <int>
#define in insert

#define endl "\n"
//var
#define L 1000000007
#define mod 100007

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 //type
#define int long long

using namespace std;
signed main()
{
  io;
  int n,k,r;
  cin>>n>>k;
  set <int> s;
  rep(i,0,n)
  {
    cin>>r;
    s.in(r);
  }
  auto it=s.rbegin();
  while(--k&&*it!=*(s.begin())) it++;
  cout<<*it-*(s.begin());

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rev(i,a,n) for (int i=a;i>n;i--)
#define repi(it,v) for (auto it=v.begin();it!=v.end();it++)
#define revi(it,v) for (auto it=v.rbegin();it!=v.rend();it++)
//gen
#define pii pair<int,int>
#define fr first
#define sc second
#define mpr make_pair
#define all(v) v.begin(),v.end()
#define init(a,i) memeset(a,i,sizeof(a))
//vec
#define vi vector <int>
#define vc vector <char>
#define pb push_back
//set
#define si set <int>
#define in insert

#define endl "\n"
//var
#define L 1000000007
#define mod 100007

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 //type
#define int long long

using namespace std;
signed main()
{
  io;
  int n,k,r;
  cin>>n>>k;
  set <int> s;
  rep(i,0,n)
  {
    cin>>r;
    s.in(r);
  }
  auto it=s.rbegin();
  while(k>0&&*it!=*(s.begin())) it++;
  cout<<*it-*(s.begin());

  return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first >= b.first);
}
vector< pair <int,int> > v;

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    int e = n-1;
    for(i=0; i<k-1; i++){
      //  cout<<v[i].second<<" "<<e<<endl;
        cost += arr[v[i].second] - arr[e];
        e = v[i+1].second;

    }
    cost += arr[e] - arr[0];
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first > b.first);
}

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    vector< pair <int,int> > v;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    int e = n-1;
    if(n==k){cout<<0<<endl; return 0;}
    for(i=0; i<k-1; i++){
        cout<<v[i].first<<" "<<v[i].second<<" cost = ";
        cost += abs(arr[v[i].second] - arr[e]);
        e = v[i].second-1;
    cout<<cost<<endl;
    }
    cost += abs(arr[e] - arr[0]);
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first >= b.first);
}

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    vector< pair <int,int> > v;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    int e = n-1;
    for(i=0; i<k-1; i++){
      //  cout<<v[i].second<<" "<<e<<endl;
        cost += arr[v[i].second] - arr[e];
        e = v[i+1].second;

    }
    cost += arr[e] - arr[0];
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first >= b.first);
}

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    vector< pair <int,int> > v;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    int e = n-1;
    i=0;
    for(auto it=v.begin(); i<k-1; it++){
      //  cout<<v[i].second<<" "<<e<<endl;
        cost += arr[it->second] - arr[e];
        it++;
        e = it->second;
        it--;

        i++;
    }

    cost += arr[e] - arr[0];
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first > b.first);
}

ll l = (1LL<<62);
ull m = (1LL<<63);
vector<int>tv(300005);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    vector< pair <int,int> > v;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);

    for(i=0; i<k-1; i++){
        tv[v[i].second] = 1;
    }
    int fst=0;
    for(i=0; i<n; i++){
        if(tv[i]==1){
            cost += arr[i-1]-arr[fst];
            fst = i;
        }
    }
    cost += arr[i-1]-arr[fst];
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first > b.first);
}

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    vector< pair <int,int> > v;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    vector<int>tv(100);

    for(i=0; i<k-1; i++){
        tv[v[i].second] = 1;
    }
    int fst=0;
    for(i=0; i<n; i++){
        if(tv[i]==1){
            cost += arr[i-1]-arr[fst];
            fst = i;
        }
    }
    cost += arr[i-1]-arr[fst];
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first >= b.first);
}
vector< pair <int,int> > v;

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    for(i=0; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    int e = n-1;
    for(i=0; i<k-1; i++){
      //  cout<<v[i].second<<" "<<e<<endl;
        cost += arr[v[i].second] - arr[e];
        e = v[i+1].second;

    }
    cost += arr[e] - arr[0];
    cout<<cost<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (a.first > b.first);
}

ll l = (1LL<<62);
ull m = (1LL<<63);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i,n,k;
    cin>>n>>k;
    ll arr[n+1];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    ll cost=0;
    vector< pair <int,int> > v;
    for(i=1; i<n; i++){
        v.push_back(make_pair(arr[i]-arr[i-1],i));
    }
    sort(v.begin(),v.end(),cmp);
    int e = n-1;
    if(n==k){cout<<0<<endl; return 0;}
    for(i=0; i<k-1; i++){
       // cout<<v[i].first<<" "<<v[i].second<<" cost = ";
        cost += abs(arr[v[i].second] - arr[e]);
        e = v[i].second-1;
    //cout<<cost<<endl;
    }
    cost += abs(arr[e] - arr[0]);
    cout<<cost<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N][2];
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x,ll pos){while(k <= siz){bit[k][pos]+=x;k += k & -k;}}
ll BITq(ll k,ll pos){ll s=0;while(k>=1){s+=bit[k][pos];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("tracing.in","r",stdin);}
void filesout(void){freopen("tracing.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Training
int main(void){
    fastio;
    ll n;
    c(n);
    ll k;
    c(k);
    ll arr[n];
    arrin(arr,n);
    ll ans = INF;
    f(i,0,n){
        if(n-k-i >= i){
            ans = min(ans,arr[n-k-i] - arr[i]);
        }
    }
    pl(ans);
}


///in this contest i will solve the most problems
#include<bits/stdc++.h>
using namespace std;
int main(void){
    long long n;
    cin>>n;
    long long k;
    cin>>k;
    long long arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    long long ans=0;
    if(n == k){
        cout<<ans;
    }
    else{
        ans = arr[n-k] - arr[0];
        cout<<ans;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N][2];
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x,ll pos){while(k <= siz){bit[k][pos]+=x;k += k & -k;}}
ll BITq(ll k,ll pos){ll s=0;while(k>=1){s+=bit[k][pos];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("tracing.in","r",stdin);}
void filesout(void){freopen("tracing.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Training
int main(void){
    fastio;
    ll n;
    c(n);
    ll k;
    c(k);
    ll arr[n];
    arrin(arr,n);
    pl(arr[k] - arr[0]);
}


///in this contest i will solve the most problems
#include<bits/stdc++.h>
using namespace std;
int main(void){
    long long n;
    cin>>n;
    long long k;
    cin>>k;
    long long arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    long long ans=0,ans2=0;
    if(n == k){
        cout<<ans;
    }
    else{
        ans = arr[n-k] - arr[0];
        ans2 = arr[n-1]- arr[k-1];
        cout<<min(ans,ans2);
    }
}


///in this contest i will solve the most problems
#include<bits/stdc++.h>
using namespace std;
int main(void){
    long long n;
    cin>>n;
    long long k;
    cin>>k;
    long long arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    long long ans=0;
    if(n == k){
        cout<<ans;
    }
    else{
        ans = arr[n-k] - arr[0];
        cout<<min(ans,arr[n-1]-arr[k-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N][2];
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x,ll pos){while(k <= siz){bit[k][pos]+=x;k += k & -k;}}
ll BITq(ll k,ll pos){ll s=0;while(k>=1){s+=bit[k][pos];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("tracing.in","r",stdin);}
void filesout(void){freopen("tracing.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Training
int main(void){
    fastio;
    ll n;
    c(n);
    ll k;
    c(k);
    ll arr[n];
    arrin(arr,n);
    pl(arr[n-k] - arr[0]);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N][2];
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x,ll pos){while(k <= siz){bit[k][pos]+=x;k += k & -k;}}
ll BITq(ll k,ll pos){ll s=0;while(k>=1){s+=bit[k][pos];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("tracing.in","r",stdin);}
void filesout(void){freopen("tracing.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Training
int main(void){
    fastio;
    ll n;
    c(n);
    ll k;
    c(k);
    ll arr[n];
    arrin(arr,n);
    ll ans = INF;
    f(i,0,n){
        if(n-k+i < n){
            ans = min(ans,arr[n-k+i] - arr[i]);
        }
    }
    pl(ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N][2];
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x,ll pos){while(k <= siz){bit[k][pos]+=x;k += k & -k;}}
ll BITq(ll k,ll pos){ll s=0;while(k>=1){s+=bit[k][pos];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("tracing.in","r",stdin);}
void filesout(void){freopen("tracing.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Training
int main(void){
    fastio;
    ll n;
    c(n);
    ll k;
    c(k);
    ll arr[n];
    arrin(arr,n);
    vll e;
    f(i,1,n){
        e.pb(arr[i] - arr[i-1]);
    }
    ll ans = arr[n-1] - arr[0];
    sort(all(e));
    reverse(all(e));
    f(i,0,k-1){
        ans -= e[i];
    }
    pl(ans);
}


///in this contest i will solve the most problems
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int k;
    cin>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int ans=0;
    if(n == k){
        cout<<ans;
    }
    else{
        ans = arr[n-k] - arr[0];
        cout<<ans;
    }
}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum1 = min(minimum1, A[i]);
            maximum1 = max(maximum1, A[i]);
        }
        for(int i = N - 1; i >= N - K; i--){
            minimum2 = min(minimum2, A[i]);
            maximum2 = max(maximum2, A[i]);
        }
        cout << min((maximum2 - minimum2), (maximum1 - minimum1)) << endl;
    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        int minimum = 10000000001;
        int maximum = 0;
        for(int i = 0; i <= N - K; i++){
            maximum = max(maximum, A[i]);
            minimum = min(minimum, A[i]);
        }
        cout << maximum - minimum << endl;

    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum1 = min(minimum1, A[i]);
            maximum1 = max(maximum1, A[i]);
        }
        for(int i = N - 1; i >= N - K + 1; i--){
            minimum2 = min(minimum2, A[i]);
            maximum2 = min(maximum2, A[i]);
        }
        cout << min((maximum1 - minimum1), (maximum2 - minimum2)) << endl;
    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum = 2000000;
    int maximum = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum = min(minimum, A[i]);
            maximum = max(maximum, A[i]);
        }
        cout << maximum - minimum << endl;
    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
       int minimum = A[0];
       int maximum = A[N-K];
       int absMinimum = 100000000;
       for(int i = 0; i < K; i++){
           minimum = A[0+i];
           maximum = A[N-K+i];
           absMinimum = min(absMinimum, abs(minimum - maximum));
       }
       cout << absMinimum << endl;

    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        int minimum = 10000000001;
        int maximum = 0;
        for(int i = 0; i < N - K; i++){
            maximum = max(maximum, A[i]);
            minimum = min(minimum, A[i]);
        }
        cout << maximum - minimum << endl;

    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum1 = min(minimum1, A[i]);
            maximum1 = max(maximum1, A[i]);
        }
        for(int i = N - 1; i >= N - K; i--){
            minimum2 = min(minimum2, A[i]);
            maximum2 = min(maximum2, A[i]);
        }
        cout << min((maximum1 - minimum1), (maximum2 - minimum2)) << endl;
    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum1 = min(minimum1, A[i]);
            maximum1 = max(maximum1, A[i]);
        }
        for(int i = N - 1; i >= N - K + 1; i--){
            minimum2 = min(minimum2, A[i]);
            maximum2 = min(maximum2, A[i]);
        }
        cout << maximum - minimum << endl;
    }

}


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

int main(int A, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum = 2000000;
    int maximum = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum = min(minimum, A[i]);
            maximum = max(maximum, A[i]);
        }
        cout << maximum - minimum << endl;
    }

}


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

int main(int B, char ** argv){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int minimum1 = 2000000;
    int maximum1 = 0;
    int minimum2 = 2000000;
    int maximum2 = 0;
    if(K == 1){
        cout << *max_element(A,A+N) - *min_element(A,A+N) << endl;
    } else if(K == N){
        cout << 0 << endl;
    } else {
        for(int i = 0; i < N - K + 1; i++){
            minimum1 = min(minimum1, A[i]);
            maximum1 = max(maximum1, A[i]);
        }
        for(int i = N - 1; i >= N - K; i--){
            minimum2 = min(minimum2, A[i]);
            maximum2 = min(maximum2, A[i]);
        }
        cout << maximum1 - minimum1 << endl;
        cout << maximum2 - minimum2 << endl;
    }

}


L = input().split()
i = 1
p = "YES"
n = int(L[0])
m = int(L[1])
if m > 0:
    T = input().split()
    T.sort()
if ('1' in T or str(n) in T):
    p = "NO"
else:
    if m > 2:
        for k in range(len(T)-4):
            if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
                p = "NO"
                break

print(p)


L = input().split()
i = 1
p = "YES"
n = int(L[0])
m = int(L[1])
if m != 0:
    T = input().split()
    T.sort()
    T = list( dict.fromkeys(T) )
    if ('1' in T or str(n) in T):
        p = "NO"
    else:
        for k in range(len(T)-4):
            if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
                p = "NO"
                break
        """while (i<n-3):
            if str(i+3) not in T:
                i = i+3
            else:
                if str(i+2) not in T:
                    i = i+2
                else:
                    if str(i+1) not in T:
                        i = i+1
                    else:
                        p = "NO"
                        break"""

print(p)


L = input().split()
i = 1
p = "YES"
m = int(L[1])
print(m)
if m > 0:
    T = input().split()
    T.sort()
    if ('1' in T or str(n) in T):
        p = "NO"
    else:
        if m > 2:
            if m == 3:
                if int(T[0]) == int(T[1]) - 1 and int(T[1]) == int(T[2]) - 1 :
                    p = "NO"
            else:
                for k in range(len(T)-2):
                    if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
                        p = "NO"
                        break

print(p)


L = input().split()
T = input().split()
T = list( dict.fromkeys(T) )
i = 1
p = "YES"
n = int(L[0])
m = int(L[1])
if ('1' in T or str(n) in T):
    p = "NO"
else:
    while (i<n-3):
        if str(i+3) not in T:
            i = i+3
        else:
            if str(i+2) not in T:
                i = i+2
            else:
                if str(i+1) not in T:
                    i = i+1
                else:
                    p = "NO"
                    break

print(p)


L = input().split()
T = input().split()
T.sort()
T = list( dict.fromkeys(T) )
i = 1
p = "YES"
n = int(L[0])
m = int(L[1])
if ('1' in T or str(n) in T):
    p = "NO"
else:
    for k in range(len(T)-4):
        if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
            p = "NO"
            break
    """while (i<n-3):
        if str(i+3) not in T:
            i = i+3
        else:
            if str(i+2) not in T:
                i = i+2
            else:
                if str(i+1) not in T:
                    i = i+1
                else:
                    p = "NO"
                    break"""

print(p)


L = input().split()
i = 1
p = "YES"
n = int(L[0])
m = int(L[1])
if m > 0:
    T = input().split()
    T.sort()
    if ('1' in T or str(n) in T):
        p = "NO"
else:
    if m > 2:
        for k in range(len(T)-4):
            if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
                p = "NO"
                break

print(p)


L = input().split()
T = input().split()
i = 1
j = 0
p = "YES"
n = int(L[0])
m = int(L[1])
if ('1' in T or str(n) in T):
    p = "NO"
else:
    while (i<n-3):
        if str(i+3) not in T:
            i = i+3
        else:
            if str(i+2) not in T:
                i = i+2
            else:
                if str(i+1) not in T:
                    i = i+1
                else:
                    p = "NO"
                    break

print(p)


L = input().split()
p = "YES"
n = int(L[0])
m = int(L[1])
if m > 0:
    T = input().split()
    T.sort()
    if ('1' in T or str(n) in T):
        p = "NO"
    else:
        if m > 2:
            if m == 3:
                if int(T[0]) == int(T[1]) - 1 and int(T[1]) == int(T[2]) - 1 :
                    p = "NO"
            else:
                for k in range(len(T)-2):
                    if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
                        p = "NO"
                        break

print(p)


L = input().split()
i = 1
p = "YES"
n = int(L[0])
m = int(L[1])
if m > 0:
    T = input().split()
    T.sort()
    if ('1' in T or str(n) in T):
        p = "NO"
    else:
        if m > 2:
            for k in range(len(T)-4):
                if int(T[k]) == int(T[k+1]) - 1 and int(T[k+1]) == int(T[k+2]) - 1 :
                    p = "NO"
                    break

print(p)


n,m = input().split()
n = int(n)
m = int(m)
if(m == 0):
	print("YES")
else:
	d = input().split()
	d.sort()
	prev,prev2 = -5,-5
	ans = 1
	for i in range(0,m):
		d[i] = int(d[i])
		if(d[i] == 1 or d[i] == n):
			ans = 0
		elif d[i] == prev + 1 and d[i] == prev2 + 2:
			ans = 0
		prev2 = prev
		prev = d[i]
	if(ans == 0):
		print("NO")
	else:
		print("YES")


n,m = input().split()
n = int(n)
m = int(m)
d = input().split()
d.sort()
prev,prev2 = -5,-5
ans = 1
for i in range(0,m):
	d[i] = int(d[i])
	if(d[i] == 1 or d[i] == n):
		ans = 0
	elif d[i] == prev + 1 and d[i] == prev2 + 2:
		ans = 0
	prev2 = prev
	prev = d[i]
if(ans == 0):
	print("NO")
else:
	print("YES")


n,m = map(int,input().split())
if m!=0:
    k = list(map(int,input().split()))
    k.sort()
    if k[0]==1 or k[-1]==n:
        print("NO")
    else:
        for i in range(m-2):
            if k[i+1]-k[i]==1 and k[i+2]-k[i+1]==1:
                print("NO")
                break
        else:
            print("YES")
else:
    print("YES")


n,m = map(int,input().split())

k = list(map(int,input().split()))
k.sort()
if k[0]==1 or k[-1]==n:
    print("NO")
else:
    for i in range(m-2):
        if k[i+1]-k[i]==1 and k[i+2]-k[i+1]==1:
            print("NO")
            break
    else:
        print("YES")


inStr=input()
n=int(inStr.split()[0])
m=int(inStr.split()[1])
ans='YES'
if not m==0:
    inStr=input()
    dirty=[int(x) for x in inStr.split()]

    sDirty=sorted(dirty)
    if sDirty[0]==1 or sDirty[-1]==n:
        ans='NO'
    else:
        for i in range(len(sDirty)-2):
            cur=sDirty[i]
            if sDirty[i+1]==cur+1 and sDirty[i+2]==cur+2:
                ans='NO'
                break

print(ans)


inStr=input()
n=int(inStr.split()[0])
m=int(inStr.split()[1])
inStr=input()
dirty=[int(x) for x in inStr.split()]

sDirty=sorted(dirty)
ans='YES'
if not m==0:
    if sDirty[0]==1 or sDirty[-1]==n:
        ans='NO'
    else:
        for i in range(len(sDirty)-2):
            cur=sDirty[i]
            if sDirty[i+1]==cur+1 and sDirty[i+2]==cur+2:
                ans='NO'
                break

print(ans)


inStr=input()
n=int(inStr.split()[0])
m=int(inStr.split()[1])
inStr=input()
dirty=[int(x) for x in inStr.split()]

sDirty=sorted(dirty)
ans='YES'
if sDirty[0]==1 or sDirty[-1]==n:
    ans='NO'
else:
    for i in range(len(sDirty)-2):
        cur=sDirty[i]
        if sDirty[i+1]==cur+1 and sDirty[i+2]==cur+2:
            ans='NO'
            break

print(ans)


n=int(input())
m=list(map(int,input().split()))
f=0
for i in m:
    if i+1 in m and i+2 in m:

        f=1
        print("NO")
        break;
    else:
        f=0
if(f==0):
    print("YES")


n=int(input())
c=int(input())
m=list(map(int,input().split()))
f=0
for i in m:
    if i+1 in m and i+2 in m:

        f=1
        print("NO")
        break;
    else:
        f=0
if(f==0):
    print("YES")


def readln(): return tuple(map(int, input().split()))

n, m = readln()
d = sorted(readln()) if m else []
if m and (d[0] == 1 or d[-1] == n) or m > 2 and [1 for i, j, k in zip(d[:-2], d[1:-1], d[2:]) if i + 2 == k]:
    print('NO')
else:
    print('YES')


n=int(input())
m=list(map(int,input().split()))
for i in range(len(m)):
    if i+1 in m:
        print("NO")
    else:
        print("YES")


n,c=int(input()),int(input())
m=list(map(int,input().split()))
f=0
for i in m:
    if i+1 in m and i+2 in m:

        f=1
        print("NO")
        break;
    else:
        f=0
if(f==0):
    print("YES")


n,c=map(int(input().split())
m=list(map(int,input().split()))
f=0
for i in m:
    if i+1 in m and i+2 in m:

        f=1
        print("NO")
        break;
    else:
        f=0
if(f==0):
    print("YES")


n,c=int(input()),int(input())
m=list(map(int,input().split()))
f=0
for i in m:
    if i+1 in m and i+2 in m:

        f=1
        print("NO")
        break;
    else:
        f=0
if(f==0):
    print("YES"


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow,pi
from bisect import bisect_left,bisect_right

def binNumber(n,size=4):
    return bin(n)[2:].zfill(size)

def iar():
    return list(map(int,input().split()))

def ini():
    return int(input())

def isp():
    return map(int,input().split())

def sti():
    return str(input())

def par(a):
    print(' '.join(list(map(str,a))))

def tdl(outerListSize,innerListSize,defaultValue = 0):
    return [[defaultValue]*innerListSize for i in range(outerListSize)]

def sts(s):
    s = list(s)
    s.sort()
    return ''.join(s)

def bis(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return [i,True]
    else:
        return [-1,False]

class pair:
    def __init__(self,f,s):
        self.fi = f
        self.se = s
    def __lt__(self,other):
        return (self.fi,self.se) < (other.fi,other.se)

#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|
#  code

if __name__ == "__main__":
    n,m = isp()

    if m != 0:
        a = iar()
        a.sort()
    else:
        print('YES')
        quit()

    c = 1
    if 1 in a or n in a:
        print('NO')
        quit()

    if m == 1 or m == 2:
        print('YES')
        quit()

    c = 2

    while c < m:
        if a[c] == (a[c-1] + 1 )and a[c] == (a[c-2] + 2):
            print('NO')
            quit()
        else:
            c += 1
    print('YES')


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow,pi
from bisect import bisect_left,bisect_right

def binNumber(n,size=4):
    return bin(n)[2:].zfill(size)

def iar():
    return list(map(int,input().split()))

def ini():
    return int(input())

def isp():
    return map(int,input().split())

def sti():
    return str(input())

def par(a):
    print(' '.join(list(map(str,a))))

def tdl(outerListSize,innerListSize,defaultValue = 0):
    return [[defaultValue]*innerListSize for i in range(outerListSize)]

def sts(s):
    s = list(s)
    s.sort()
    return ''.join(s)

class pair:
    def __init__(self,f,s):
        self.fi = f
        self.se = s
    def __lt__(self,other):
        return (self.fi,self.se) < (other.fi,other.se)

#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|
#  code
def BinS(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return True
    else:
        return False
if __name__ == "__main__":
    n,m = isp()
    a = iar()
    a.sort()
    c = 1
    if 1 in a or n in a:
        print('NO')
        quit()

    while c != n:
        q1 = BinS(a,c+1)
        q2 = BinS(a,c+2)
        q3 = BinS(a,c+3)
        if q1 and q2 and q3:
            print('NO')
            quit()
        else:
            if not q1:
                c += 1
            elif not q2:
                c += 2
            else:
                c += 3
    if c == n:
        print('YES')


n,d=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))
flag=0
for i in range(d-2):
    if l[i+1]==l[i]+1 and l[i+2]==l[i]+2:
        print ("NO")
        flag=1
        break
if(flag==0):
    print ("YES")


n,d=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))
flag=0
if(l[0]==1 or l[-1]==n):
    print ("NO")
else:
    for i in range(d-2):
        if l[i+1]==l[i]+1 and l[i+2]==l[i]+2:
            print ("NO")
            flag=1
            break
    if(flag==0):
        print ("YES")


import sys
n,d=list(map(int,input().split()))
if(d==0):
    print ("YES")
    sys.exit(0)
l=sorted(list(map(int,input().split())))
flag=0
if(l[0]==1 or l[-1]==n):
    print ("NO")
else:
    for i in range(d-2):
        if l[i+1]==l[i]+1 and l[i+2]==l[i]+2:
            print ("NO")
            flag=1
            break
    if(flag==0):
        print ("YES")


n,d=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))
flag=0
if(l[0]==1 or l[-1]==n):
    print ("NO")
elif(d==0):
    print ("YES")
else:
    for i in range(d-2):
        if l[i+1]==l[i]+1 and l[i+2]==l[i]+2:
            print ("NO")
            flag=1
            break
    if(flag==0):
        print ("YES")


a,b=tuple(input().split(" "))
if b=="0":
    print("NO")
    exit(0)
a=int(a)
b=int(b)
c=[int(x) for x in input().split(" ")]
c.sort()
if 1 in c or a in c:
    print("NO")
    exit(0)
for x in c:
    if x in c and x+1 in c and x+2 in c:
        print("NO")
        exit(0)
print("YES")


a,b=tuple(input().split(" "))
a=int(a)
b=int(b)
c=[int(x) for x in input().split(" ")]
c.sort()
if 1 in c or a in c:
    print("NO")
    exit(0)
for x in c:
    if x in c and x+1 in c and x+2 in c:
        print("NO")
        exit(0)
print("YES")


a,b=tuple(input().split(" "))
if b=="0":
    print("YES")
    exit(0)
a=int(a)
b=int(b)
c=[int(x) for x in input().split(" ")]
c.sort()
if 1 in c or a in c:
    print("NO")
    exit(0)
for x in c:
    if x in c and x+1 in c and x+2 in c:
        print("NO")
        exit(0)
print("YES")


a,b=tuple(input().split(" "))
if b==0:
    print("NO")
    exit(0)
a=int(a)
b=int(b)
c=[int(x) for x in input().split(" ")]
c.sort()
if 1 in c or a in c:
    print("NO")
    exit(0)
for x in c:
    if x in c and x+1 in c and x+2 in c:
        print("NO")
        exit(0)
print("YES")


a=list(map(int,input().split()))
m=list(map(int,input().split()))
m.sort()
Max,c=0,1
if m[0]!=1 and m[-1]!=a[0]:
    for i in range(len(m)-1):
        if m[i]==m[i+1]-1:
            c+=1
        else:
            if c>Max:
                Max=c
            c=1
    if Max<3:
        print('YES')
    else:
        print('NO')
else:
    print('NO')


a=list(map(int,input().split()))

if a[1]==0:
    print('YES')
else:
    m=list(map(int,input().split()))
    m.sort()
    Max,c=0,1
    if m[0]!=1 and m[-1]!=a[0]:
        for i in range(len(m)-1):
            if m[i]==m[i+1]-1:
                c+=1
            else:
                if c>Max:
                    Max=c
                c=1
        if Max<3:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')


a=list(map(int,input().split()))

if a[1]==0:
    print('YES')
else:
    m=list(map(int,input().split()))
    m.sort()
    Max,c=0,1
    if m[0]!=1 and m[-1]!=a[0]:
        for i in range(len(m)-1):
            if m[i]==m[i+1]-1:
                c+=1
                if c>Max:
                    Max=c
            else:
                c=1
        if Max<3:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')


a=list(map(int,input().split()))
m=list(map(int,input().split()))
m.sort()
Max,c=0,1
if a[1]==0:
    print('YES')
else:
    if m[0]!=1 and m[-1]!=a[0]:
        for i in range(len(m)-1):
            if m[i]==m[i+1]-1:
                c+=1
            else:
                if c>Max:
                    Max=c
                c=1
        if Max<3:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')


I = lambda: map(int, input().split())

n, m = I()

if m:
    D = sorted(I())
    if 1 in D or n in D or any(D[i]==D[i+1]-1==D[i+2]-2 for i in range(m-2)):
        print('NO')
    else:
        print('YES')
else:
    print('YES')


I = lambda: map(int, input().split())

n, m = I()
D = sorted(I())

print('NO' if n in D or any(D[i]==D[i+1]-1==D[i+2]-2 for i in range(m-2))
           else 'YES')


I = lambda: map(int, input().split())

n, m = I()

if m:
    D = sorted(I())
    print('NO' if n in D or any(D[i]==D[i+1]-1==D[i+2]-2 for i in range(m-2))
               else 'YES')
else:
    print('YES')


I = lambda: map(int, input().split())

n, m = I()
D = sorted(I())

print('NO' if any(D[i]==D[i+1]-1==D[i+2]-2 for i in range(m-2)) else 'YES')


n, m=map (int, input ().split ())
l=[]
if m>0:

	k=list(map (int, input ().split ()))
	l=k
if (1 in l) or (n in l):
	print ('NO')
elif m==0:
	print ('YES' )
else:
	l.sort()
	flag =0
	for i in range(m-2):
		if l[i+1]-l[i] ==1 and l[i+2]-l[i+1] ==1:
			flag=1
			break
	if flag ==1:
		print ('NO')
	else:
		print ('YES')


n, m=map (int, input ().split ())
l=[]
if m>0:
	k=list(map (int, input ().split ()))
	l=k
if (1 in l) or (n in l):
	print ('NO')
elif m==0:
	print ('YES' )
else:
	l.sort()
	flag =0
	for i in range(m-2):
		if l[i+1]-l[i] ==1 and l[i+2]-l[i+1] ==1:
			flag=1
			break
	if flag ==1:
		print ('NO')
	else:
		print ('YES')


n, d=map (int, input ().split ())
l=list(map (int, input ().split ()))
if (1 in l) or (n in l):
	print ('NO')
else:
	l.sort()
	flag =0
	for i in range(d-3):
		if l[i+1]-l[i] ==1 and l[i+2]-l[i+1] ==1:
			flag=1
			break
	if flag ==1:
		print ('NO')
	else:
		print ('YES')


flag=0
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
if(l[0]==1 or l[-1]==n):
    print("NO")
else:
    for i in range(m-1):
        if(l[i+1]==l[i]+1 and l[i+2]==l[i+1]+1):
            print("NO")
            flag=1
            break
    if(flag==0):
        print("YES")


flag=0
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
if(m==0):
    print("YES")
elif(l[0]==1 or l[-1]==n):
    print("NO")
else:
    for i in range(m-2):
        if(l[i+1]==l[i]+1 and l[i+2]==l[i+1]+1):
            print("NO")
            flag=1
            break
    if(flag==0):
        print("YES")


flag=0
n,m=map(int,input().split())
if(m==0):
    print("YES")
    exit()
l = sorted(list(map(int, input().split())))
if(l[0]==1 or l[-1]==n):
    print("NO")
else:
    for i in range(m-2):
        if(l[i+1]==l[i]+1 and l[i+2]==l[i+1]+1):
            print("NO")
            flag=1
            break
    if(flag==0):
        print("YES")


flag=0
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
if(l[0]==1 or l[-1]==n):
    print("NO")
else:
    for i in range(m-2):
        if(l[i+1]==l[i]+1 and l[i+2]==l[i+1]+1):
            print("NO")
            flag=1
            break
    if(flag==0):
        print("YES")


n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
count=1
stair=0
flag=0
for i in range(m-1):
    if(l[i+1]-l[i]==1):
        count+=1
        stair+=1
        if(count>2):
            print("NO")
            flag=1
    else:
        stair+=1
        count=0
    if(flag==1):
        break
if(stair==m-1):
    print("YES")


# coding: utf-8
n, m = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
if n in d:
    print('NO')
    exit()
d.sort()
i = 0
while i < m-2:
    if d[i+2]-d[i+1]==1:
        if d[i+1]-d[i]==1:
            print('NO')
            break
        else:
            i += 1
    else:
        i += 2
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if not m:
    print('YES')
    exit()
d = [int(i) for i in input().split()]
if n in d or 1 in d:
    print('NO')
    exit()
d.sort()
i = 0
for i in range(m-2):
    if d[i+2]-d[i+1]==1 and d[i+1]-d[i]==1:
        print('NO')
        break
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if m:
    d = [int(i) for i in input().split()]
if n in d:
    print('NO')
    exit()
d.sort()
i = 0
while i < m-2:
    if d[i+2]-d[i+1]==1:
        if d[i+1]-d[i]==1:
            print('NO')
            break
        else:
            i += 1
    else:
        i += 2
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if not m:
    print('YES')
    exit()
d = [int(i) for i in input().split()]
if n in d or 1 in d:
    print('NO')
    exit()
d.sort()
i = 0
for i in range(m-1):
    if d[i+2]-d[i+1]==1 and d[i+1]-d[i]==1:
        print('NO')
        break
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if not m:
    print('YES')
    exit()
d = [int(i) for i in input().split()]
if n in d or 1 in d:
    print('NO')
    exit()
d.sort()
i = 0
while i < m-2:
    if d[i+2]-d[i+1]==1 and d[i+1]-d[i]:
        print('NO')
        break
    else:
        i += 1
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if not m:
    print('YES')
    exit()
d = [int(i) for i in input().split()]
if n in d:
    print('NO')
    exit()
d.sort()
i = 0
while i < m-2:
    if d[i+2]-d[i+1]==1:
        if d[i+1]-d[i]==1:
            print('NO')
            break
        else:
            i += 1
    else:
        i += 2
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if not m:
    print('YES')
    exit()
d = [int(i) for i in input().split()]
if n in d or 1 in d:
    print('NO')
    exit()
d.sort()
i = 0
while i < m-2:
    if d[i+2]-d[i+1]==1 and d[i+1]-d[i]==1:
        print('NO')
        break
    else:
        i += 1
else:
    print('YES')


# coding: utf-8
n, m = [int(i) for i in input().split()]
if not m:
    print('YES')
    exit()
d = [int(i) for i in input().split()]
if n in d or 1 in d:
    print('NO')
    exit()
d.sort()
i = 0
while i < m-2:
    if d[i+2]-d[i+1]==1:
        if d[i+1]-d[i]==1:
            print('NO')
            break
        else:
            i += 1
    else:
        i += 2
else:
    print('YES')


n, m = map(int, input().split())
if m == 0: print('YES')
else:
    t = list(map(int, input().split()))
    t.sort()
    if t[0] == 1 or t[-1] == n: print('NO')
    else:
        k = 2
        s = 0
        for i in t:
            if i == k:
                s += 1
                k += 1
                if s > 1:
                    print('NO')
                    break
            else:
                s = 0
                k = i + 1
        if k == t[-1] + 1: print('YES')


n, m = map(int, input().split())
if m == 0: print('YES')
else:
    t = list(map(int, input().split()))
    t.sort()
    if t[0] == 1 or t[-1] == n: print('NO')
    else:
        k = s = 0
        for i in t:
            if i == k:
                s += 1
                k += 1
                if s > 1:
                    s = -1
                    break
            else: k, s = i + 1, 0
        print('YNEOS'[s == -1 :: 2])


n, m = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
if t[0] == 1 or t[-1] == n: print('NO')
else:
    k = 2
    s = 0
    for i in t:
        if i == k:
            s += 1
            k += 1
            if s > 1:
                print('NO')
                break
        else:
            s = 0
            k = i + 1
    if k == t[-1] + 1: print('YES')


n, m = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
if t[0] == 1 or t[-1] == n: print('NO')
else:
    k = 2
    s = 0
    for i in t:
        if i == k:
            s += 1
            k += 1
            if s > 1:
                print('NO')
                break
        else:
            s = 0
            k = i + 1


n, m = map(int, input().split())
if m == 0: print('YES')
else:
    t = list(map(int, input().split()))
    t.sort()
    if t[0] == 1 or t[-1] == n: print('NO')
    else:
        k = 2
        s = 0
        for i in t:
            if i == k:
                s += 1
                k += 1
                if s > 1:
                    s = -1
                    break
            else:
                s = 0
                k = i + 1
        print('YNEOS'[s == -1 :: 2])


n, m = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
if len(t) == 0: print('YES')
elif t[0] == 1 or t[-1] == n: print('NO')
else:
    k = 2
    s = 0
    for i in t:
        if i == k:
            s += 1
            k += 1
            if s > 1:
                print('NO')
                break
        else:
            s = 0
            k = i + 1
    if k == t[-1] + 1: print('YES')


n, m = [int(x) for x in input().split()]
l = sorted([int(x) for x in input().split()])
for i in range(m - 2):
	if l[i + 2] == l[i + 1] + 1 and l[i + 1] == l[i] + 1:
		print('NO')
		break
else:
	print('YES')


n, m = [int(x) for x in input().split()]
l = sorted([int(x) for x in input().split()])
if l[0] == 1 or l[-1] == n:
	print('NO')
	exit()
for i in range(m - 2):
	if l[i + 2] == l[i + 1] + 1 and l[i + 1] == l[i] + 1:
		print('NO')
		break
else:
	print('YES')


n, m = [int(x) for x in input().split()]
if m:
	l = sorted([int(x) for x in input().split()])
else:
	l = []
if len(l) and (l[0] == 1 or l[-1] == n):
	print('NO')
	exit()
for i in range(m - 2):
	if l[i + 2] == l[i + 1] + 1 and l[i + 1] == l[i] + 1:
		print('NO')
		break
else:
	print('YES')


n, m = [int(x) for x in input().split()]
l = sorted([int(x) for x in input().split()])
if len(l) and (l[0] == 1 or l[-1] == n):
	print('NO')
	exit()
for i in range(m - 2):
	if l[i + 2] == l[i + 1] + 1 and l[i + 1] == l[i] + 1:
		print('NO')
		break
else:
	print('YES')


n,m=map(int,input().split())
if m==0:
    print('YES')
    exit()
a=list(map(int,input().split()))

def cal(a,m,n):

    if (1 in a) or (n in a):
        return ('NO')

    a.sort()

    i=0
    j=1
    while j<m:
        if a[j]==a[i]+1:
            j+=1
        else:
            i=j
            j+=1
        if j-i+1==3:
            return('NO')
        j+=1
    return('YES')
print(cal(a,m,n))


n,m=map(int,input().split())
if m==0:
    print('YES')
    exit()
a=list(map(int,input().split()))

def cal(a,m,n):

    if (1 in a) or (n in a):
        return ('NO')

    a.sort()

    i=0
    j=1
    while j<m:
        if a[j]==a[i]+1:
            j+=1
        else:
            i=j
            j+=1
        if j-i+1==3:
            return('NO')
        #print(a[i],a[j])
    return('YES')

print(cal(a,m,n))


n,m=map(int,input().split())
if m==0:
    print('YES')
    exit()
a=list(map(int,input().split()))

def cal(a,m,n):

    if (1 in a) or (n in a):
        return ('NO')

    a.sort()

    i=0
    j=1
    c=0
    while j<m:
        if a[j]==a[j-1]+1:
            c+=1
        else:
            c=0
        j+=1
        if c==2:
            return('NO')
        #print(a[i],a[j])
    return('YES')

print(cal(a,m,n))


n,m=map(int,input().split())
a=list(map(int,input().split()))

def cal(a,m,n):
    if (1 in a) or (n in a):
        return ('NO')

    a.sort()

    i=0
    j=1
    while j<m:
        if a[j]==a[i]+1:
            j+=1
        else:
            i=j
            j+=1
        if j-i+1==3:
            return('NO')
        j+=1
    return('YES')
print(cal(a,m,n))


n, m = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()

cur = 0

flag = 1

for i in range(m-1):
    if A[i+1]-A[i] == 1:
        cur += 1
        if cur >= 2:
            print("NO")
            flag = 0
            break
    else:
        cur = 0

if flag:
    print("YES")


n, m = list(map(int, input().split()))

fff = 1

if m == 0:
    print("YES")
    fff = 0

if fff :

    A = list(map(int, input().split()))

    A.sort()

    cur = 0

    flag = 1

    if A[-1] == n:
        print("NO")
        flag = 0

    if 1 in A:
        print("NO")
        flag = 0

    for i in range(m-1):
        if A[i+1]-A[i] == 1 and flag:
            cur += 1
            if cur >= 2:
                print("NO")
                flag = 0
                break
        else:
            cur = 0

    if flag:
        print("YES")


n, m = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()

cur = 0

flag = 1

if A[-1] == n:
    print("NO")
    flag = 0

for i in range(m-1):
    if A[i+1]-A[i] == 1:
        cur += 1
        if cur >= 2:
            print("NO")
            flag = 0
            break
    else:
        cur = 0

if flag:
    print("YES")


n, m = list(map(int, input().split()))

fff = 1

if m == 0:
    print("YES")
    fff = 0

if fff :

    A = list(map(int, input().split()))

    A.sort()

    cur = 0

    flag = 1

    if A[-1] == n:
        print("NO")
        flag = 0

    if 1 in A and flag:
        print("NO")
        flag = 0

    for i in range(m-1):
        if A[i+1]-A[i] == 1 and flag:
            cur += 1
            if cur >= 2:
                print("NO")
                flag = 0
                break
        else:
            cur = 0

    if flag:
        print("YES")


n, m = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()

cur = 0

flag = 1

if A[-1] == n:
    print("NO")
    flag = 0

for i in range(m-1):
    if A[i+1]-A[i] == 1 and flag:
        cur += 1
        if cur >= 2:
            print("NO")
            flag = 0
            break
    else:
        cur = 0

if flag:
    print("YES")


n, m = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()

cur = 0

flag = 1

if A[-1] == m:
    print("NO")
flag = 0

for i in range(m-1):
    if A[i+1]-A[i] == 1:
        cur += 1
        if cur >= 2:
            print("NO")
            flag = 0
            break
    else:
        cur = 0

if flag:
    print("YES")


n, m = list(map(int, input().split()))

fff = 1

if m == 0:
    print("YES")
    fff = 0

if fff :

    A = list(map(int, input().split()))

    A.sort()

    cur = 0

    flag = 1

    if A[-1] == n:
        print("NO")
        flag = 0

    for i in range(m-1):
        if A[i+1]-A[i] == 1 and flag:
            cur += 1
            if cur >= 2:
                print("NO")
                flag = 0
                break
        else:
            cur = 0

    if flag:
        print("YES")


n, m = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()

cur = 0

flag = 1

if A[-1] == m:
    print("NO")
    flag = 0

for i in range(m-1):
    if A[i+1]-A[i] == 1:
        cur += 1
        if cur >= 2:
            print("NO")
            flag = 0
            break
    else:
        cur = 0

if flag:
    print("YES")


n,k=map(int,input().split())
if(k==0):
    print("YES")
else:
    d=list(map(int,input().split()))
    d.sort()
    if(d[0]==1 or d[k-1]==n):
        print("NO")
    else:
        l=1
        f=1
        for i in range(1,k):
            if(d[i]-d[i-1]==1):
                l+=1
            else:
                l=1
            if(l==3):
                f=0
                print("NO")
                break
        if(f):
            print("YES")


import sys
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
flag=0
for i in range(k-3):
    flag=1
    if(l[i+1]==l[i]+1  and l[i+2]==l[i]+2):
        print("NO")
        sys.exit()
if(flag==0):
    print("NO")
else:
    print("YES")


import sys
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
cnt=0
for i in range(k-1):
    cnt=cnt+1
    if(l[i+1]-l[i]>1):
        if(cnt>2):
            print("NO")
            sys.exit()
        else:
            cnt=0
print("YES")


import sys
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
cnt=0
for i in range(k-1):
    if(l[i+1]-l[i]==1):
        cnt=cnt+1
    if(cnt>1):
        print("NO")
        sys.exit()
print("YES")


n,m=map(int,input().split())
l=[]
if(m>0):
    l=list(map(int,input().split()))
    l.sort()
if(m>0 and (l[0]==1 or l[-1]==n)):
    print('NO')
    exit()
i=0
if(m>=3):
    while(i<m):
        if(i<m-2 and l[i+1]-l[i]==1 and l[i+2]-l[i+1]==1):
            print('NO')
            exit()
        i+=1
print("YES")


n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(m>0 and l[0]==1 or l[-1]==n):
    print('NO')
    exit()
i=0
if(m>=3):
    while(i<m):
        if(i<m-2 and l[i+1]-l[i]==1 and l[i+2]-l[i+1]==1):
            print('NO')
            exit()
        i+=1
print("YES")


n,m=map(int,input().split())
l=[]
if(m>0):
    l=list(map(int,input().split()))
    l.sort()
if(m>0 and l[0]==1 or l[-1]==n):
    print('NO')
    exit()
i=0
if(m>=3):
    while(i<m):
        if(i<m-2 and l[i+1]-l[i]==1 and l[i+2]-l[i+1]==1):
            print('NO')
            exit()
        i+=1
print("YES")


n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(l[0]==1 or l[-1]==n):
    print('NO')
    exit()
i=0
if(m>=3):
    while(i<m):
        if(i<m-2 and l[i+1]-l[i]==1 and l[i+2]-l[i+1]==1):
            print('NO')
            exit()
        i+=1
print("YES")


n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
if a[0] == 1 or a[-1] == n:
    print('NO')
else:
    last, s, ans = None, 0, 'YES'
    for i in a:
        if last is None:
            last = i
        elif last + 1 == i:
            s += 1
        else:
            s = 0
        if s == 2:
            ans = 'NO'
            break

        last = i
    print(ans)


n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
if a[0] == 1 or a[-1] == n:
    print('NO')
else:
    last, s, ans = None, 0, 'YES'
    for i in a:
        if last is None:
            last = i
        elif last + 1 == i:
            s += 1
        else:
            s = 0
        if s == 2:
            ans = 'NO'
            break

        last = i
print(ans)


n, m = map(int, input().split())
if m == 0:
    print('YES')
else:
    a = sorted(list(map(int, input().split())))
    if a[0] == 1 or a[-1] == n:
        print('NO')
    else:
        last, s, ans = None, 0, 'YES'
        for i in a:
            if last is None:
                last = i
            elif last + 1 == i:
                s += 1
            else:
                s = 0
            if s == 2:
                ans = 'NO'
                break

            last = i
        print(ans)


n,m = map(int, input().split())
L = sorted(map(int, input().split()))
a = []
if L[0] == 1 or L[m-1] == n:
    print("NO")
else:
    for i in range(1,m):
        a.append(L[i]-L[i-1])
    f = 0
    for i in range(1,m-1):
        if a[i] == 1 and a[i-1] == 1:
            f = 1
            break
    print("YNEOS"[f::2])


n,m = map(int, input().split())
if m == 0:
    print("YES")
    quit()
L = sorted(map(int, input().split()))
if L[0] == 1 or L[m-1] == n:
    print("NO")
else:
    a = []
    for i in range(1,m):
        a.append(L[i]-L[i-1])
    f = 0
    for i in range(1,m-1):
        if a[i] == 1 and a[i-1] == 1:
            f = 1
            break
    print("YNEOS"[f::2])


g=input()
n,m=[int(x) for x in g.split()]
if m==0:
	print("YES")
else:
	r=input()
	li=[]
	if m>2:
		for x in r.split():
			li.append(int(x)-1)
	else:
		if m==1:
			li.append(int(r)-1)
	li=sorted(li)
	if 0 in li or (n-1) in li:
		print("NO")
	else:
		d=0
		flag=0
		l=0
		if m>2:
			for i in range(m-1):
				if li[i+1]-li[i]==1:
					l+=1
					if l==1:
						t=i
					if i==t:
						d+=1
					if i!=t:
						d=1
					t=i+1
				if d>=2:
					flag=1
					print("NO")
					break
			if flag==0:
				print("YES")
		else:
			print("YES")


g=input()
n,m=[int(x) for x in g.split()]
r=input()
li=[]
for x in r.split():
	li.append(int(x)-1)
li=sorted(li)
if 0 in li or (n-1) in li:
	print("NO")
else:
	d=0
	flag=0
	l=0
	if m>2:
		for i in range(m-1):
			if li[i+1]-li[i]==1:
				l+=1
				if l==1:
					t=i
				if i==t:
					d+=1
				if i!=t:
					d=1
				t=i+1
			if d>=2:
				flag=1
				print("NO")
				break
		if flag==0:
			print("YES")
	else:
		print("YES")


g=input()
n,m=[int(x) for x in g.split()]
r=input()
li=[]
if m>2:
	for x in r.split():
		li.append(int(x)-1)
else:
	if m==1:
		li.append(int(r)-1)
li=sorted(li)
if 0 in li or (n-1) in li:
	print("NO")
else:
	d=0
	flag=0
	l=0
	if m>2:
		for i in range(m-1):
			if li[i+1]-li[i]==1:
				l+=1
				if l==1:
					t=i
				if i==t:
					d+=1
				if i!=t:
					d=1
				t=i+1
			if d>=2:
				flag=1
				print("NO")
				break
		if flag==0:
			print("YES")
	else:
		print("YES")


g=input()
n,m=[int(x) for x in g.split()]
r=input()
li=[]
for x in r.split():
	li.append(int(x)-1)
li=sorted(li)
if 0 in li or (n-1) in li:
	print("NO")
else:
	d=0
	flag=0
	l=0
	for i in range(m-1):
		if li[i+1]-li[i]==1:
			l+=1
			if l==1:
				t=i
			if i==t:
				d+=1
			if i!=t:
				d=1
			t=i+1
		if d>=2:
			flag=1
			print("NO")
			break
	if flag==0:
		print("YES")


g=input()
n,m=[int(x) for x in g.split()]
if m==0:
	print("YES")
else:
	r=input()
	li=[]
	if m>1:
		for x in r.split():
			li.append(int(x)-1)
	else:
		if m==1:
			li.append(int(r)-1)
	li=sorted(li)
	if 0 in li or (n-1) in li:
		print("NO")
	else:
		d=0
		flag=0
		l=0
		if m>2:
			for i in range(m-1):
				if li[i+1]-li[i]==1:
					l+=1
					if l==1:
						t=i
					if i==t:
						d+=1
					if i!=t:
						d=1
					t=i+1
				if d>=2:
					flag=1
					print("NO")
					break
			if flag==0:
				print("YES")
		else:
			print("YES")


g=input()
n,m=[int(x) for x in g.split()]
if m==0:
	print("YES")
else:
	r=input()
	li=[]
	if m>1:
		for x in r.split():
			li.append(int(x)-1)
	else:
		if m==1:
			li.append(int(r)-1)
	li=sorted(li)
	print(li)
	if 0 in li or (n-1) in li:
		print("NO")
	else:
		d=0
		flag=0
		l=0
		if m>2:
			for i in range(m-1):
				if li[i+1]-li[i]==1:
					l+=1
					if l==1:
						t=i
					if i==t:
						d+=1
					if i!=t:
						d=1
					t=i+1
				if d>=2:
					flag=1
					print("NO")
					break
			if flag==0:
				print("YES")
		else:
			print("YES")


def bin(arr, n):
  l = 0
  r = len(arr) - 1
  while l <= r:
    m = (l + r) // 2
    if arr[m] == n:
      return True
    elif arr[m] < n:
      l = m + 1
    else:
      r = m - 1
  return False

n, m = [int(i) for i in input().strip().split()]
arr = [int(i) for i in input().strip().split()]
arr.sort()
if arr[0] == 1 or arr[-1] == n:
  print('NO')
else:
  b = True
  for i in arr:
    if bin(arr, i+1) and bin(arr, i+2):
      print('NO')
      b = False
      break
  if b:
    print('YES')


def bin(arr, n):
  l = 0
  r = len(arr) - 1
  while l <= r:
    m = (l + r) // 2
    if arr[m] == n:
      return True
    elif arr[m] < n:
      l = m + 1
    else:
      r = m - 1
  return False

n, m = [int(i) for i in input().strip().split()]
if m == 0:
  print('YES')
else:
  arr = [int(i) for i in input().strip().split()]
  arr.sort()
  if arr[0] == 1 or arr[-1] == n:
    print('NO')
  else:
    b = True
    for i in arr:
      if bin(arr, i+1) and bin(arr, i+2):
        print('NO')
        b = False
        break
    if b:
      print('YES')