#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n, k;
   cin >> n >> k;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];

   int ans = 0;
   rep(l, 0, k + 1) rep(r, 0, k - l + 1) {
      if (l + r > n) continue;
      int d = k - l - r;
      int now = 0;
      vector<int> s;
      rep(i, 0, l) {
         now += a[i];
         s.push_back(a[i]);
      }
      rep(i, n - r, n) {
         now += a[i];
         s.push_back(a[i]);
      }
      sort(s.begin(), s.end());
      rep(i, 0, d) {
         if (i >= s.size()) break;
         if (s[i] >= 0) break;
         now -= s[i];
      }
      ans = max(ans, now);
   }
   cout << ans << endl;
   return 0;
}
// 2020-07-04 23:45:06
#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; }

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