#include <bits/stdc++.h>
using namespace std;
int a[107], b[107];
int main() {
  int n, k;
  int ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= k && i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      int l = j, r = i - j, cnt = 0, res = 0;
      for (int p = 1; p <= l; ++p) b[++cnt] = a[p];
      for (int p = n; p > n - i + j; --p) b[++cnt] = a[p];
      sort(b + 1, b + cnt + 1);
      for (int p = 1; p <= k - i && p <= cnt; ++p)
        if (b[p] >= 0)
          break;
        else
          b[p] = 0;
      for (int p = 1; p <= cnt; ++p) res += b[p];
      ans = max(ans, res);
    }
  }
  cout << ans;
}
