#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int long long MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int ans = -INF;
  int lim = min(n, k);
  for (int l = 0; l <= lim; l++) {
    for (int r = 0; r <= lim - l; r++) {
      vector<int> te;
      int sum = 0;
      for (int i = 0; i < l; i++) {
        sum += v[i];
        if (v[i] < 0) {
          te.push_back(v[i]);
        }
      }
      for (int i = 0; i < r; i++) {
        sum += v[n - i - 1];
        if (v[n - i - 1] < 0) {
          te.push_back(v[n - i - 1]);
        }
      }
      int a = k - (l + r);
      int b = te.size();
      sort(te.begin(), te.end());
      for (int tt = 0; tt <= min(a, b); tt++) {
        if (tt != 0) {
          sum -= te[tt - 1];
        }
        if (ans < sum) {
          ans = sum;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
