#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
};
ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
typedef vector<vector<Edge>> Graph;
//BEGIN CUT HERE
struct RUP {
	int n;
	vector<int> dat, laz;
	const int def = INT_MAX;
	RUP() {}
	RUP(int n_) { init(n_); }
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, def);
		laz.clear();
		laz.resize(2 * n - 1, -1);
	}
	inline void eval(int len, int k) {
		if (laz[k] < 0) return;
		if (k * 2 + 1 < n * 2 - 1) {
			laz[k * 2 + 1] = laz[k];
			laz[k * 2 + 2] = laz[k];
		}
		dat[k] = laz[k];
		laz[k] = -1;
	}
	int update(int a, int b, int x, int k, int l, int r) {
		eval(r - l, k);
		if (r <= a || b <= l) return dat[k];
		if (a <= l && r <= b) return laz[k] = x;
		eval(r - l, k);
		dat[k] = min(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
			update(a, b, x, k * 2 + 2, (l + r) / 2, r));
		return dat[k];
	}
	int query(int a, int b, int k, int l, int r) {
		eval(r - l, k);
		if (r <= a || b <= l) return def;
		if (a <= l && r <= b) return dat[k];
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	void update(int a, int b, int x) {
		update(a, b, x, 0, 0, n);
	}
	int query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};
//END CUT HERE
signed main(void) {
	int n, k;
	cin >> n >> k;
	deque<int> v;
	REP(i, n) {
		int cv;
		scanf("%d", &cv);
		v.push_back(cv);
	}

	int ans = INT_MIN;

	REP(a, n + 1) {
		if (a > k) continue;
		REP(b, k - a + 1) {
			if (a + b > n) continue;
			int sum = 0;
			vector<int> ac;

			deque<int> rv(v);

			REP(i, a) {
				ac.push_back(rv.front());
				sum += rv.front();
				rv.pop_front();
			}
			REP(i, b) {
				ac.push_back(rv.back());
				sum += rv.back();
				rv.pop_back();
			}

			sort(ALL(ac));

			int rest = k - a - b;
			
			REP(i, min(rest,(int)ac.size())) {
				if (ac[i] >= 0) break;
				sum -= ac[i];
			}
			chmax(ans, sum);
		}

	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256