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

#define ll long long


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if (k == n) {
		ll sum = 0;
		for (int i = 1; i < n - 1; i++) {
			sum += a[i];
		}
		sum += max(a[0], a[n - 1]) - min(a[0], a[n - 1]);
		cout << sum << "\n";
	}
	else {
		ll ans = -1e12;
		vector<int> poz, neg;
		for (int poc = 0; poc < n - 1 - k; poc++) {
			for (int kraj = poc + k - 1; kraj < n; kraj++) {
				poz.clear();
				neg.clear();
				
				ll temp = 0;
				for (int i = poc + 1; i < kraj; i++) {
					if(a[i] >= 0)
						poz.push_back(a[i]);
					else 
						neg.push_back(a[i]);	
				}
				sort(poz.begin(), poz.end(), greater<int>());
				sort(neg.begin(), neg.end());

				if (poz.size() >= k - 2) {
					for (int i = 0; i < k - 2; i++) {
						temp += poz[i];
					}
				}
				else {
					for (int x : poz) {
						temp += x;
					}
					for (int i = 0; i < k - poz.size(); i++) {
						temp += neg[i];
					}
				}

				temp += max(a[poc], a[kraj]) - min(a[poc], a[kraj]);
				ans = max(ans, temp);
			}
		}
		cout << ans << "\n";
	}
	
	return 0;
}