#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,k1,maxx=0,minn=0,l=0;
int a[400001],b[400001];
int ans;
int main()
{
//freopen("kth.in","r",stdin);
//freopen("kth.out","w",stdout);
cin>>n>>k1;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
{maxx=a[i];minn=a[i];
for(int k=i;k<=j;k++)
{maxx=max(maxx,a[k]);
minn=min(minn,a[k]);
}
ans=maxx-minn;
b[l]=ans;l++;
//cout<<"{"<<ans<<" "<<i<<" "<<j<<"}"<<endl;
}
sort(b+1,b+l+1);
cout<<b[l-k1+1];
return 0;
}