#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int n, K;
    cin >> n >> K;
    int v[n];
    rep(i, n) cin >> v[i];
    int mx = min(n, K);
    int ans = 0;
    for (int i = 0; i <= mx; i++){
        for (int j = 0; j <= i; j++){
            vec v_s;
            for (int k = 0; k < j; k++){
                v_s.push_back(v[k]);
            }
            for (int k = n - 1; k > (n - 1) - (i - j); k--){
                v_s.push_back(v[k]);
            }
            sort(v_s.begin(), v_s.end());
            // for (int k = 0; k < v_s.size(); k++){
            //     cout << v_s[k] << " ";
            // }cout << endl;
            
            int sm = 0;
            rep(k, v_s.size()){
                if(k < K - i && v_s[k] < 0) continue;
                sm += v_s[k];
            }
            // cout << sm << endl;
            ans = max(sm, ans);
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N= 51;
const int M= 101;

int dp[N][N][M];

void solve() {
        int n, k; cin >> n>> k;

        memset(dp, -1, sizeof(dp));
        vector<int> v(n);
        for (auto& i: v) cin >> i;

        function<int(int, int, int)> calc= [&](int i, int j, int cnt)->int {
                if (cnt< 0) return -1e18;
                if (cnt== 0) return 0;
                if (i> j) return 0;

                int &ret= dp[i][j][cnt];
                if (ret!= -1) return ret;
                ret= 0;

                ret= max(ret, calc(i+ 1, j, cnt- 1)+ v[i]);
                ret= max(ret, calc(i+ 1, j, cnt- 2));
                ret= max(ret, calc(i, j- 1, cnt- 1)+ v[j]);
                ret= max(ret, calc(i, j- 1, cnt- 2));
                return ret;
        };

        cout << calc(0, n- 1, k)<< "\n";
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}
