#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

const ll N_MAX = 50;
const ll K_MAX = 100;
const ll V_I_MAX = 10000000;

ll N, K;
vector<ll> v;


void solve() {
	ll ans = 0;
	ll toruinit=0;

	if(N<K){
			
			vector<ll> t;
			rep(i,v.size())t.push_back(v[i]);
			sort(all(t));
			
			rep(k,K-v.size()){
				if(t[k]<0)t[k]=0;
				else break;
			}
			ll sum=accumulate(t.begin(), t.end(), 0LL);//総和
			chmax(ans,sum);
			t.erase(all(t));
			p(ans)		;return;
	}

	if(K%2==0)toruinit=K/2;
	else toruinit=(K-1)/2;

	for(ll torucount=toruinit;torucount<=K;torucount++){
		if(torucount==0)continue;
		
		if((ll)(v.size())<=torucount){
			vector<ll> t;
			rep(i,v.size())t.push_back(v[i]);
			rep(k,K-torucount){
				if(t[k]<0)t[k]=0;
				else break;
			}
			ll sum=accumulate(t.begin(), t.end(), 0LL);//総和
			chmax(ans,sum);
			t.erase(all(t));
			continue;			
		}
		debug(toruinit);
		for(ll j=0;j<=torucount;j++){//区切りの位置
			vector<ll> t;
			for(ll k=0;k<j;k++){
				t.push_back(v[k]);
			}
			debug(j);
			//debug(t);
			for(ll k=N-1;N-torucount+j<=k;k--){//??
				t.push_back(v[k]);
			}
			
			sort(all(t));
			
			rep(k,K-torucount){
				if(t[k]<0)t[k]=0;
				else break;
			}
			debug(t);
			ll sum=accumulate(t.begin(), t.end(), 0LL);//総和
			//if(chmax(ans,sum))debug(t);
			chmax(ans,sum);
			t.erase(all(t));
		}


	}






	printf("%lld\n", ans);
}

signed main() {
	scanf("%lld%lld", &N, &K);
	v.assign(N,0);
	bool a=true;
	rep(i, N) {
		cin >> v[i];
		if(v[i]>0)a=false;
	}
	if(a){
		p(0);return 0;
	}

	//rui.assign(N+1,0);
	//rep(i,N)rui[i+1]=rui[i]+v[i];

	solve();
	return 0;
}


Measured memory_bytes: 256