#include <bits/stdc++.h>
int com(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int N, K;
  scanf("%d %d", &N, &K);
  int V[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &V[i]);
  }
  int R = K;
  if (N < K) {
    R = N;
  }
  int ans = 0;
  for (int i = 0; i <= R; i++) {
    for (int j = 0; j <= i; j++) {
      int A = j;
      int B = i - j;
      int D = K - (A + B);
      int arr[A + B];
      int k = 0;
      for (k = 0; k < A; k++) {
        arr[k] = V[k];
      }
      int a = 0;
      int vl = N - 1;
      while (a < B) {
        arr[k++] = V[vl--];
        a++;
      }
      qsort(arr, i, sizeof(int), com);
      int count = 0;
      for (int l = 0; l < D; l++) {
        if (l < i && arr[l] < 0) {
          count -= arr[l];
        }
      }
      for (int l = 0; l < i; l++) {
        count += arr[l];
      }
      if (count > ans) {
        ans = count;
      }
    }
  }
  printf("%d", ans);
  return 0;
}
