#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() {
  deque<int long long> d;
  int n, k;
  cin >> n >> k;
  vector<int long long> v(n);
  int long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    d.push_back(v[i]);
    sum += v[i];
  }
  int long long ans = -INF;
  int long long idou = 0;
  vector<int long long> t1;
  for (int l = 0; l <= min(n, k); l++) {
    if (l != 0) {
      t1.push_back(v[l - 1]);
      idou += v[l - 1];
    }
    int long long idou2 = idou;
    vector<int long long> t2;
    t2 = t1;
    for (int r = 0; r <= min(n, k) - l; r++) {
      if (r != 0) {
        t2.push_back(v[n - r]);
        idou2 += v[n - r];
      }
      sort(t2.begin(), t2.end());
      int long long kari = idou2;
      int long long a = min(n, k) - (l + r);
      int long long b = t2.size();
      ans = max(kari, ans);
      if (min(a, b) != 0) {
        for (int te = 0; te < min(a, b); te++) {
          kari -= t2[te];
          ans = max(kari, ans);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
