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

using namespace std;
	
vector<ll> current;
ll* dynamic;

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

ll src2_what(ll first, int l, int d) {
	cout << l << " " << d << " " << first << " " << current[d] << "\n";
	if (d - l == 1)
		return current[d] - first;
	return src2_what(first - current[d], l, d - 1);
}

int main() {
	ll n, k;
	int i;
	cin >> n >> k;
	dynamic = new ll[500000]();

	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.resize(k);
		j = 0;
		for (i = 0; i < n; i++)
			if (bitmask[i]) {
				current[j] = all[i];
				j++;
			}
		ll srcres;
		if (n <= 3)
			srcres = search(current[0], 0, k - 1);
		else
			srcres = src2_what(current[0], 0, k - 1);
		if (srcres > max)
			max = srcres;
		current.resize(0);
	} while (prev_permutation(bitmask.begin(), bitmask.end()));
	cout << max;

	return EXIT_SUCCESS;
}