#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long ma = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<int> s(0);
  for (int a = 0; a <= k; a++) {
    for (int b = 0; a + b <= k; b++) {
      s.clear();
      for (int i = 0; i < a; i++) {
        s.push_back(v[i]);
      }
      for (int j = 0; j < b; j++) {
        s.push_back(v[n - 1 - j]);
      }
      sort(s.begin(), s.end());
      int x = 0;
      while (s[x] < 0 && (a + b + x) < k && x < s.size()) {
        s[x] = 0;
        x++;
      }
      long long sum = 0;
      for (int l = 0; l < s.size(); l++) {
        sum += (long long)s[l];
      }
      ma = max(ma, sum);
    }
  }
  cout << ma << endl;
}
