#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long N, K, V[1 << 18], ans = -(1LL << 60);

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> V[i];

	for (int i = 0; i < N; i++) {
		for (int j = i - 1; j < N; j++) {
			int t1 = N - (j - i + 1);
			int rem = K - t1; if (rem < 0) continue;

			long long sum = 0; vector<long long> A;
			for (int k = 0; k < i; k++) A.push_back(V[k]);
			for (int k = j + 1; k < N; k++) A.push_back(V[k]);
			sort(A.begin(), A.end());
			for (int k = 0; k < A.size(); k++) sum += A[k];
			for (int k = 0; k < min((int)A.size(), rem); k++) sum -= min(0LL, A[k]);
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}