#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2000000000;
const int INF2 = 10000000;
const double Micro = 1e-5;
int UnUsedVariable() {
  if (INF || Micro || MOD || INF2) {
    ;
  }
  return 0;
}
inline int isEven(int x) { return x % 2 == 0; }
inline int isOdd(int x) { return x % 2 == 1; }
int EintN(int array[], const int num) {
  for (int i = 0; i < num; i++) {
    printf("%d ", array[i]);
  }
  printf("\n");
  ;
  return 0;
}
int EintNN(const int heighth, const int width, int array[heighth][width]) {
  for (int i = (0); i < (heighth); i++) {
    for (int k = (0); k < (width); k++) {
      { printf("%d ", array[i][k]); }
    }
    printf("\n");
    ;
  }
  printf("\n");
  ;
  return 0;
}
int E(string str, const int num) {
  cerr << str << " is " << num << " now." << endl;
  return 0;
}
int experiment() {
  int ans;
  ans = 0;
  int N, K;
  cin >> N >> K;
  K = min(K, 2 * N);
  int V[N + 2];
  for (int i = (1); i < (N + 1); i++) {
    cin >> V[i];
  };
  V[0] = 0;
  V[N + 1] = 0;
  int fore[N + 2], back[N + 2];
  fore[0] = 0;
  for (int i = (1); i < (N + 2); i++) {
    fore[i] = fore[i - 1] + V[i];
  }
  back[0] = 0;
  for (int i = (1); i < (N + 2); i++) {
    back[i] = back[i - 1] + V[N + 1 - i];
  }
  vector<int> sortArray;
  int maxget = min(N, K);
  for (int getnum = (0); getnum <= (maxget); getnum++) {
    int MAXpush = min(maxget, K - getnum);
    for (int leftget = (0); leftget <= (getnum); leftget++) {
      int SumOfGet = fore[leftget] + back[getnum - leftget];
      for (int i = (1); i <= (leftget); i++) {
        sortArray.push_back(V[i]);
      }
      for (int i = (1); i <= (getnum - leftget); i++) {
        sortArray.push_back(V[(N + 1) - i]);
      }
      sort(sortArray.begin(), sortArray.end());
      int MinusNum = (lower_bound(sortArray.begin(), sortArray.end(), 0)) -
                     (sortArray.begin());
      int SumOfRemove = 0;
      for (int i = (0); i < (min(MinusNum, MAXpush)); i++) {
        SumOfRemove += sortArray[i];
      }
      ans = max(ans, SumOfGet - SumOfRemove);
      sortArray.clear();
    }
  }
  {
    cout << (ans) << endl;
    return 0;
  };
  return 0;
}
signed main() {
  assert(1);
  experiment();
  return 0;
}
