#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> value(n);
  for (int i = 0; i < n; i++) cin >> value[i];
  if (k >= 2 * n) k = 2 * n;
  vector<int> lsum(n, 0), rsum(n, 0), ldp(k + 1, 0), rdp(k + 1, 0);
  vector<vector<int> > lneg(n, vector<int>()), rneg(n, vector<int>());
  int l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    l += value[i];
    r += value[n - 1 - i];
    lsum[i] = l;
    rsum[i] = r;
    if (value[i] < 0) {
      for (int w = i; w < n; w++) lneg[w].emplace_back(-value[i]);
      for (int w = n - 1 - i; w < n; w++) rneg[w].emplace_back(-value[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!lneg[i].empty())
      sort(lneg[i].begin(), lneg[i].end(), [](int a, int b) { return a > b; });
    if (!rneg[i].empty())
      sort(rneg[i].begin(), rneg[i].end(), [](int a, int b) { return a > b; });
  }
  for (int i = 1; i <= k; i++) {
    int maxnum = 0;
    int t = (i > n ? n : i);
    for (int j = 0; j <= i / 2; j++) {
      if (t - 1 - j < 0) break;
      int temp = lsum[t - 1 - j];
      for (int w = 1; w <= j && w <= lneg[t - 1 - j].size(); w++) {
        temp += lneg[t - 1 - j][w - 1];
      }
      if (temp > maxnum) maxnum = temp;
    }
    ldp[i] = (ldp[i - 1] < maxnum ? maxnum : ldp[i - 1]);
  }
  for (int i = 1; i <= k; i++) {
    int maxnum = 0;
    int t = (i > n ? n : i);
    for (int j = 0; j <= i / 2; j++) {
      if (t - 1 - j < 0) break;
      int temp = rsum[t - 1 - j];
      for (int w = 1; w <= j && w <= rneg[t - 1 - j].size(); w++) {
        temp += rneg[t - 1 - j][w - 1];
      }
      if (temp > maxnum) maxnum = temp;
    }
    rdp[i] = (rdp[i - 1] < maxnum ? maxnum : rdp[i - 1]);
  }
  int result = 0;
  for (int i = 0; i <= k; i++)
    if (result < ldp[i] + rdp[k - i]) result = ldp[i] + rdp[k - i];
  cout << result << endl;
  return 0;
}
