#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int INF=2147483647;
int n,k,a[100];
ll ans;
ll doo(int x,int y){
	vector <int> v;
	for(int i=1;i<=x;i++)
		v.push_back(a[i]);
	for(int i=n;i>y;i--)
		v.push_back(a[i]);
	int lim=x+n-y;
	if(lim>k)
		return 0;
	else{
		lim=k-lim;
		ll sum=0;
		sort(v.begin(),v.end());
		for(int i=0;i<v.size();i++)
			if(v[i]<0&&lim>0)
				lim--;
			else
				sum+=v[i];
//		cout<<x<<' '<<y<<" "<<sum<<endl;
		return sum;
	}
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=0;i<=n;i++)
		for(int j=n;j>=i;j--)
			if(i+n-j<=k)
				ans=max(ans,doo(i,j));
	cout<<ans<<endl;
	return 0;
}