#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

//左からA個、右からB個取り出す。最後にC個戻す。
//このA, B, Cを1から100まで試す。
// B>K-Aならばbreak

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll N, K;
    cin >> N >> K;
    deque<ll> V;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        V.push_back(tmp);
    }

    ll max_ans = 0;
    ll ans;
    REP(a, 105) {  //右からとる
        if (a > N || a > K) continue;
        REP(b, N - a + 1) {  //左からとる
            ans = 0;
            if (b > N || b > K) continue;
            if (a + b > N) continue;
            if (a + b > K) continue;
            ll c = K - (a + b);  //戻す回数
            if (c < 0) continue;
            deque<ll> V_copy = V;
            vector<ll> vec;
            priority_queue<ll, vector<ll>, greater<ll>> neg;
            debug(a, b, c);
            REP(j, a) {
                ll left;
                left = V_copy.back();
                V_copy.pop_back();
                vec.push_back(left);
                if (left < 0) neg.push(left);
            }
            REP(i, b) {
                ll right;
                right = V_copy.front();
                V_copy.pop_front();
                vec.push_back(right);
                if (right < 0) neg.push(right);
            }
            debug(vec);
            // if(!neg.empty()) debug(neg.top());
            debug("-----");

            ans = accumulate(vec.begin(), vec.end(), 0LL);
            debug(ans);
            REP(i, c) {
                if (!neg.empty()) {
                    ans -= neg.top();
                    neg.pop();
                }
            }
            if (ans > max_ans) max_ans = ans;
        }
        debug(max_ans);
        debug("~~~~");
    }
    cout << max_ans << endl;

    return 0;
}


Measured memory_bytes: 256