#include <iostream>
#include <array>
#include<algorithm>


int carobnjak(long long arr[], long long n, int k)
{
	long long max = 0;
	while (k != 1)
	{
		for (int i = 0; i < n; i++)
			for (int j = 0; j <= k; j++)
			{
				if (arr[i] > arr[j])
				{
					if (arr[i] - arr[j] > max)
						max = arr[i] - arr[j];
				}
				else
				{
					if (arr[j] - arr[i] > max)
						max = arr[j] - arr[i];
				}
			}
		k--;
	}
	return max;
}

int main()
{
	long long n, k;
	long long a[10000];
	std::cin >> n >> k;
	for (int i = 0; i < n; i++)
		std::cin >> a[i];
	std::cout << carobnjak(a, n, k);
	return 0;
}