#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  int v[n];
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int cur = 0;
  int opr;
  vector<int> t1, t2;
  for (int i = 0; i <= n; i++) {
    t2.clear();
    for (int j = n; j >= i; j--) {
      if (j < n) t2.push_back(v[j]);
      opr = i + (n - j);
      if (opr > k) break;
      cur = 0;
      vector<int> al;
      for (auto p : t1) al.push_back(p);
      for (auto p : t2) al.push_back(p);
      sort(al.begin(), al.end());
      for (auto x : al) cur += x;
      opr = k - opr;
      for (int i = 0; i < al.size(); i++) {
        if (opr > 0) {
          opr--;
          cur = max(cur, cur - al[i]);
        }
      }
      res = max(res, cur);
    }
    if (i < n) t1.push_back(v[i]);
  }
  cout << res;
  return 0;
}
