#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

//#define LOCAL true;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a, b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}

#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>
bool chmax(T &a, const T &b) {
    if(a<b) {
        a=b;
        return 1;
    }
    return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
    if(b<a) {
        a=b;
        return 1;
    }
    return 0;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

ll n, k;
Vec v;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    Vec r;
    Vec rsum(n+1);
    Vec l;
    Vec lsum(n+1);
    l.pb(0);
    rep(i, n) {
        ll tmp;
        cin>>tmp;
        l.pb(tmp);
        r.pb(tmp);
    }
    r.pb(0);
    reverse(ALL(r));
    ll m=min(n, k);

    rep(i, m) {
        if(i>0) {
            lsum[i+1]=lsum[i]+l[i+1];
            rsum[i+1]=rsum[i]+r[i+1];
        } else {
            lsum[i+1]=l[i+1];
            rsum[i+1]=r[i+1];
        }
    }

//    dbg(l);
//    dbg(lsum);
//    dbg(r);
//    dbg(rsum);

    ll ans=0;
    Vec lhand;
    Vec rhand;
    REP(a, 0, m+1) {
        REP(b, 0, m+1-a) {
            Vec trashl=l;
            Vec trashr=r;
            sort(trashl.begin()+1, trashl.begin()+a+1);
            sort(trashr.begin()+1, trashr.begin()+b+1);
            ll tmpc = 0;
             REP(c, 0, min(min(k-(a+b), a),n)+1) {
                 tmpc += trashl[c];
                 ll tmpd = 0;
                 REP(d, 0, min(min(k-(a+b+c), b),n)+1) {
//                    dbg(a);
//                    dbg(b);
//                    dbg(c);
//                    dbg(d);
                    tmpd += trashr[d];
//                     dbg(trashl);
//                     dbg(trashr);
//                     dbg(tmpc);
//                     dbg(tmpd);
                     ans=max(ans, lsum[a]+rsum[b]-tmpc-tmpd);
                    // dbg(lsum[a]+rsum[b]-tmpc-tmpd);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256