#include <bits/stdc++.h>
using namespace std;
int Sum(const vector<int>& Jwels, size_t a, size_t b, size_t suteru) {
  int val = 0;
  list<int> Hands;
  while (a > 0) {
    const int temp = Jwels[a - 1];
    val += temp;
    if (temp < 0) Hands.emplace_back(temp);
    --a;
  }
  while (b > 0) {
    const int temp = Jwels[Jwels.size() - b];
    val += temp;
    if (temp < 0) Hands.emplace_back(temp);
    --b;
  }
  Hands.sort();
  for (auto Itr = Hands.cbegin(); suteru > 0 && Itr != Hands.cend();
       --suteru, ++Itr) {
    if (*Itr > 0) break;
    val += -(*Itr);
  }
  return val;
}
int main() {
  size_t n, k;
  cin >> n >> k;
  vector<int> Jwels(n, 0);
  for (size_t i = 0; i < n; ++i) cin >> Jwels[i];
  const int min_pop = min(n, k);
  int max_val = 0;
  for (size_t a = 0; a <= min_pop; ++a) {
    for (size_t b = 0; b <= min_pop - a; ++b) {
      const int val = Sum(Jwels, a, b, k - (a + b));
      if (max_val < val) max_val = val;
    }
  }
  cout << max_val << endl;
  return 0;
}
