// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> V(N);
  rep (i, N) cin >> V[i];

  deque<ll> treasures;
  rep (i, N) treasures.push_back(V[i]);
  ll ans = numeric_limits<ll>::min();
  for (ll numpop = min(N, K); numpop >= 0; numpop--) {
    ll numpush = K - numpop;
    for (ll numpopL = 0; numpopL < numpop + 1; numpopL++) {
      ll numpopR = numpop - numpopL;
      vector<ll> mytreasures;
      rep (i, numpopL) {
        mytreasures.push_back(treasures.at(i));
        // cerr <<"L"<< mytreasures.back() << endl;
      }
      rep (i, numpopR) {
        mytreasures.push_back(treasures.at(N - i - 1));
        // cerr <<"R"<< mytreasures.back() << endl;
      }
      ll sum = 0;
      for (const auto mytreasure : mytreasures) {
        sum += mytreasure;
      }
      sort(mytreasures.begin(), mytreasures.end());
      for (ll i = 0; i < mytreasures.size() && i < numpush && mytreasures.at(i) < 0;
             ++i) {
        sum -= mytreasures.at(i);
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 50, K = 100;
ll mem[N+2][N+1][K+1];
ll opt(int i, int j, int k, vector<int>& v) {
    ll& ans = mem[i+1][j+1][k];
    if(ans == -1) {
        if(i <= j) {
            ans = max({
                k >= 1 ? v[i] + opt(i + 1, j, k - 1, v) : 0,
                k >= 1 ? v[j] + opt(i, j - 1, k - 1, v) : 0,
                k >= 2 ? opt(i + 1, j, k - 2, v) : 0,
                k >= 2 ? opt(i, j - 1, k - 2, v) : 0
            });
        } else {
            ans = 0;
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    cin >> v;
    memset(mem, -1, sizeof mem);
    ll ans = 0;
    for(int kk = 0; kk <= k; kk++) {
        ans = max(ans, opt(0, n - 1, kk, v));
    }
    cout << ans << endl;
    return 0;
}
