#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define ll long long

using namespace std;
	
ll* current;

ll search(ll first, int l, int d) {
	if (l == d)
		return first;
	ll xy_op = search(current[l] - current[d], l, d - 1);
	ll yx_op = search(current[d] - current[l], l + 1, d);
	if (xy_op >= yx_op)
		return xy_op;
	else
		return yx_op;
}

int main() {
	ll n, k;
	int i;
	cin >> n >> k;
	vector<ll> all(n);
	vector<ll> results(n);
	for (i = 0; i < n; i++)
		cin >> all[i];

	ll max = -1 * pow(2, 63);
	int j;
	string bitmask(k, 1);
	bitmask.resize(n, 0);
	do {
		current = new ll[k];
		j = 0;
		for (i = 0; i < n; i++)
			if (bitmask[i]) {
				current[j] = all[i];
				j++;
			}
		ll srcres = search(current[0], 0, k - 1);
		if (srcres > max)
			max = srcres;
		free(current);
	} while (prev_permutation(bitmask.begin(), bitmask.end()));

	cout << max;

	return EXIT_SUCCESS;
}