#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, e, f, g, i, j, n, k, m, l;
  long long v[100], sum = -100000000, h;
  h = 0;
  cin >> n >> k;
  long long w[100];
  for (i = 0; i < n; i++) {
    cin >> v[i];
  }
  if (k > 2 * n) k = 2 * n;
  a = n / 2;
  m = 0;
  for (i = 0; i < a; i++) {
    l = k - i + 1;
    if (l > n) l = n;
    for (m = 0; m < l; m++) {
      h = 0;
      for (j = 0; j < k - i; j++) {
        if (j < m)
          w[j] = v[j];
        else
          w[j] = v[n - 1 + m - j];
        h = h + w[j];
      }
      sort(w, w + k - i);
      g = 0;
      while (g < i && w[g] < 0) {
        h = h - w[g];
        g++;
      }
      if (h > sum) sum = h;
    }
  }
  cout << sum;
  return 0;
}
