#include <bits/stdc++.h>
using namespace std;
int n, k, a[55], sum[55];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], sum[i] = sum[i - 1] + a[i];
  set<int> S;
  long long ans = 0;
  for (int lef = 0; lef < min(n, k + 1); ++lef) {
    if (lef > 0) S.insert(a[lef]);
    set<int> S2;
    S2 = S;
    for (int rig = 0; rig <= min(n - lef, k - lef); ++rig) {
      if (rig > 0) S2.insert(a[n - rig + 1]);
      long long res = sum[lef] + sum[n] - sum[n - rig];
      int cnt = 0;
      for (auto val : S2) {
        if (cnt + lef + rig == k || val > 0) break;
        ++cnt;
        res -= val;
      }
      ans = max(ans, res);
    }
  }
  cout << ans;
  return 0;
}
