#include <bits/stdc++.h>
using namespace std;
const long long mod = 2019;
const long long INF = 1e+14;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
void Yes() {
  cout << "Yes" << endl;
  exit(0);
}
void No() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> V;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    V.push_back(a);
  }
  int d = min(N, K);
  vector<long long> ans;
  long long kai = 0;
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < i; j++) {
      ans.clear();
      long long count = 0;
      for (int k = 0; k < j; k++) {
        count += V[k];
        ans.push_back(V[k]);
      }
      for (int k = N - 1; k >= N - i + j; k--) {
        count += V[k];
        ans.push_back(V[k]);
      }
      sort(ans.begin(), ans.end());
      int k = 0;
      while (ans[k] < 0 && k < K - i) {
        count -= ans[k];
        k++;
      }
      kai = max(count, kai);
    }
  }
  cout << kai << endl;
}
