#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < (n); ++i) cin >> v[i];
  vector<long long> sl(n + 1);
  for (int i = 0; i < (n); ++i) sl[i + 1] = sl[i] + v[i];
  reverse((v).begin(), (v).end());
  vector<int> rv(n);
  for (int i = 0; i < (n); ++i) rv[i] = v[i];
  reverse((v).begin(), (v).end());
  vector<long long> sr(n + 1);
  for (int i = 0; i < (n); ++i) sr[i + 1] = sr[i] + rv[i];
  long long ans = 0;
  for (int l = 0; l < (k + 1); ++l)
    for (int r = 0; r < (k - l + 1); ++r) {
      if (l + r > n) continue;
      int ret = k - l - r;
      vector<int> hand;
      for (int i = 0; i < (l); ++i) hand.push_back(v[i]);
      for (int i = 0; i < (r); ++i) hand.push_back(rv[i]);
      sort((hand).begin(), (hand).end());
      long long now = sl[l] + sr[r];
      for (int i = 0; i < (ret); ++i) {
        if (i >= hand.size()) break;
        if (hand[i] > 0) break;
        now -= hand[i];
      }
      ans = max(ans, now);
    }
  cout << ans << endl;
  return 0;
}
