#include <bits/stdc++.h>
static const int MAX = 50;
using namespace std;
int N, K, ans;
int D[MAX + 2];
int solve() {
  for (int a = 0; a <= K && a < N; a++) {
    for (int b = 0; a + b < K && a + b < N; b++) {
      vector<int> V;
      int sum = 0;
      for (int i = 0; i < a; i++) {
        V.push_back(D[i]);
        sum += D[i];
      }
      for (int i = 0; i < b; i++) {
        V.push_back(D[N - 1 - i]);
        sum += D[N - 1 - i];
      }
      ans = max(sum, ans);
      sort(V.begin(), V.end());
      int i = 0;
      while (i < V.size() && a + b + i < K && V[i] < 0) {
        sum -= V[i++];
      }
      ans = max(sum, ans);
    }
  }
  return ans;
}
int main(void) {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    int v;
    scanf("%d", &v);
    D[i] = v;
  }
  printf("%d\n", solve());
}
