#include <bits/stdc++.h>
#include <vector>
#include <math.h>
using namespace std;

void makeCombiUtil(vector<vector<int> >& ans,
	vector<int>& tmp, int n, int left, int k)
{
	if (k == 0) {
		ans.push_back(tmp);
		return;
	}
	for (int i = left; i <= n; ++i)
	{
		tmp.push_back(i);
		makeCombiUtil(ans, tmp, n, i + 1, k - 1);

		tmp.pop_back();
	}
}


vector<vector<int> > makeCombi(int n, int k)
{
	vector<vector<int> > ans;
	vector<int> tmp;
	makeCombiUtil(ans, tmp, n, 1, k);
	return ans;
}

int main()
{
	
	int x,y,min,mink,truemin=-2147483600;
	int n,k,i,j;
	cin>>n;
	cin>>k;
	int *niz = new int[n];
	int *kniz = new int[k];
	for(i=0;i<n;i++)
		cin>>niz[i];
	vector<vector<int> > ans = makeCombi(n, k);
	for (i = 0; i < ans.size(); i++) {
		min=0;
		for (j = 0; j < k; j++) {
			kniz[j] = niz[ans.at(i).at(j)-1];
		}
		for (x = 0; x < k-1; x++) {
			mink=0;
			for (y = 0; y <k ; y++) {
				
				if(y<=x)
					mink=mink+kniz[y];
				else
					mink=mink-kniz[y];
			}
			if(abs(mink)>min){	
				min=abs(mink);
			}

		}
		if(min>truemin){
			truemin=min;
		}
	}

	cout<<truemin;
	delete [] niz;
	delete [] kniz;


	return 0;
}