#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;


int solve(vector<int> &arr) {
	cout << endl;
	for (auto x : arr)
		cout << x << " ";
	if (arr.size() == 1)
		return arr[0];
	if (arr.size() == 2)
		return max(arr[0] - arr[arr.size()-1], arr[arr.size()-1] - arr[0]);

	vector<int> nArr;
	int mn = min(arr[0] - arr[arr.size()-1], arr[arr.size()-1] - arr[0]);
	nArr.push_back(mn);
	for (int i = 1; i < arr.size() - 1; i++) {
		nArr.push_back(arr[i]);
	}
	return solve(nArr);
}

int main() {


	// vector<int> arr2 = {-1, -2, -3};

	// cout << endl << solve(arr2) << endl;

	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for (auto &x : arr)
		cin >> x;

	if (n == k) {
		int s = 0;
		for (auto x : arr)
			s += x;

		cout << max(s - 2*arr[0], s - 2*arr[n-1]);
		return 0;
	}

	int ans = 0;

	for (int i = 0; i < n-k+1; i++) {

		int curr = -arr[i];

		vector<int> arr2 = arr;
		sort(arr2.begin() + i + 1, arr2.end(), greater<int>());
		for (int j = 1; j < k; j++) {
			curr += arr2[j+i];
		}

		ans = max(curr, ans);

	}


	for (int i = n-1; i >= k-1; i--) {

		int curr = -arr[i];

		vector<int> arr2 = arr;
		sort(arr2.begin(), arr2.end() - (n - i));

		// cout << endl << " | ";
		// for (auto x : arr2)
		// 	cout << x << " ";
		// cout << "| " << endl;

		for (int j = 1; j < k; j++) {
			curr += arr2[i - j];
		}

		ans = max(curr, ans);

	}


	cout << ans << endl;







	return 0;
}