#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n);
    rep(0,i,n)cin>>v[i];
    ll ans=0;
    rep(0,i,min(n,k)+1){
        rep(0,j,min(n,k)-i+1){
            vector<ll> t;
            rep(0,l,i)t.push_back(v[l]);
            rep(0,r,j)t.push_back(v[n-1-r]);
            sort(t.begin(),t.end());
            rep(0,l,min(k-i-j,(ll)t.size())){
                if(t[l]<0)t[l]=0;
            }
            ans=max(ans,accumulate(t.begin(),t.end(),0LL));
        }
    }
    cout<<ans<<endl;
}