#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,K;
	cin>>N>>K;
	vector<int> a(N);
	rep(i,0,N) cin>>a[i];
	
	int res=0;
	rep(l,0,N+1) rep(r,0,N+1) rep(p,0,N+1) {
		if (l+r>N || p>=l+r || l+r+p>K) continue;
		
		int sum=0;
		priority_queue<int> q;
		rep(i,0,N) if (i<l || N-r<=i) {
			sum+=a[i];
			q.emplace(-a[i]);
		}
		
		//~ cerr<<l+r<<" "<<sz(q)<<endl;
		
		rep(i,0,p) {
			sum+=q.top();
			q.pop();
		}
		
		res=max(res,sum);
	}
	cout<<res<<"\n";
}
