#include <bits/stdc++.h>

using namespace std;


int del(int arr[], int n, int x)
{

int i;
for (i=0; i<n; i++)
    if (arr[i] == x)
        break;

if (i < n)
{
    n = n - 1;
    for (int j=i; j<n; j++)
        arr[j] = arr[j+1];
}
 
return n;
}



int main()
{
	int n, k;
	cin >> n >> k;
	
	int a[n];
	
	int i;
	
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];		
	}
	
	int m;
	
	int odg = 0;
	
	int max = a[0], min = a[0];
	
	for (int i = 0; i<k-1; i++)
	{
	
		for (int j = 0; j < n; j++)
		{
			if (max<a[j]) max = a[j];
		
			if (min>a[j]) min = a[j];
	} 
	odg = max - min;
	
	int x = a[min];
	
	m = del(a, n, x);
	
}
	cout << odg << endl;
	
	return 0;
}