#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;

    vector<int> v(n);

    loop(i,n){
        cin >> v[i];
    }

    ll result = 0;

    // i個の宝石を取る
    loop(i,min(n,k)+1){
        // j個だけ左から取る
        loop(j,i+1){
            vector<int> minusJewel = {};
            ll tmp = 0; 
            loop(l,j){
                tmp += v[l];
                if(v[l] < 0)minusJewel.push_back(v[l]);
            }
            loop(l,i-j){
                tmp += v[n-1-l];
                if(v[n-l-1] < 0)minusJewel.push_back(v[n-l-1]);
            }
            sort(minusJewel.begin(),minusJewel.end());
            ll minusNum = minusJewel.size();
            
            loop(l,min(k-i, minusNum)){
                tmp -= minusJewel[l];
            }
        
            result = max(tmp, result);
        }
    }

    cout << result << endl;
}
// 2020-07-15 23:13:36
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

vector<int> vs;
int dp[55][55][105];
int rec(int l, int r, int k) {
  if(dp[l][r][k] >= 0) return dp[l][r][k];
  chmax(dp[l][r][k], 0);
  if(l == r) return dp[l][r][k];
  if(k >= 1) {
    chmax(dp[l][r][k], rec(l+1, r, k-1) + vs[l]);
    chmax(dp[l][r][k], rec(l, r-1, k-1) + vs[r-1]);
  }
  if(k >= 2) {
    chmax(dp[l][r][k], rec(l+1, r, k-2));
    chmax(dp[l][r][k], rec(l, r-1, k-2));
  }
  return dp[l][r][k];
}
void answer() {
  int n, k;
  cin >> n >> k;
  vs.resize(n);
  rep(i, n) cin >> vs[i];
  repc(i, n) repc(j, n) repc(ki, k) dp[i][j][ki] = -1;
  cout << rec(0, n, k) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}