#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
int n,k,v[51],a[101];
LL ans;
LL solve(int x,int y)
{
	int tot=0;LL sum=0;
	for(int i=1;i<=x;i++) a[++tot]=v[i];
	for(int i=n;i>=n-y+1;i--) a[++tot]=v[i];
	sort(a+1,a+tot+1);
	for(int i=1;i<=min(k-x-y,tot);i++) if(a[i]>0) sum+=a[i];
	for(int i=k-x-y+1;i<=tot;i++) sum+=a[i];
	return sum;
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	for(int i=0;i<=min(n,k);i++)
	  for(int j=0;j<=min(k-i,n-i);j++)
	  {
	  	ans=max(ans,solve(i,j));
	  }
	printf("%lld",ans);
	return 0;
}