#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>
#include<math.h>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	vector<Int> v(N);
	for (Int i = 0; i < N; i++) {
		cin >> v[i];
	}

	vector<Int> left(N);//左からi番目までの累積和
	left[0] = v[0];
	for (Int i = 0; i < N-1; i++) {
		left[i + 1] = left[i] + v[i + 1];
	}
	vector<Int> right(N);//右からi番目までの累積和
	right[0] = v[N - 1];
	for (Int i = 0; i < N-1; i++) {
		right[i + 1] = right[i] + v[N - 1 - (i + 1)];
	}
	
	Int ans = 0;
	Int res;
	Int cnt;
	for (Int i = 0; i <= N; i++) {//左からi個取る
		for (Int j = 0; j <= N; j++) {//右からj個取る
			if (i + j > N || i + j > K)continue;

			if (i != 0 && j != 0) {
				 res = left[i-1] + right[j-1];
			}
			else if (i == 0 && j == 0) {
				res = 0;
			}
			else if (i == 0) {
				res = right[j-1];
			}
			else {
				res = left[i - 1];
			}

			cnt = K - i - j;
			if (cnt > 0) {
				priority_queue<Int,vector<Int>,greater<Int>> res2;
				for (Int k = 0; k < i; k++) {
					res2.push(v[k]);
				}
				for (Int l = 0; l < j; l++) {
					res2.push(v[N-1-l]);
				}

				while (cnt > 0) {
					if (res2.empty())break;
					if (res2.top() < 0) {
						res -= res2.top();
						res2.pop();
						cnt--;
					}
					else {
						break;
					}
				}
			}

			ans = max(ans, res);
		}
	}

	cout << ans << "\n";
}

Measured memory_bytes: 256