#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
bool f(string s) {
  bool ans = true;
  for (int i = 0; i < s.size() / 2; ++i) {
    if (s[i] != s[s.size() / 2 + i]) {
      ans = false;
      break;
    }
  }
  return ans;
}
long long a[55], n, k;
long long dfs(long long l, long long r) {
  long long s;
  vector<long long> vec;
  for (int i = 0; i <= l; i++) vec.push_back(a[i]);
  for (int i = r; i < n; i++) vec.push_back(a[i]);
  sort(vec.begin(), vec.end());
  long long maxs;
  maxs = k - vec.size();
  if (maxs < 0) return 0;
  s = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] < 0 && maxs > 0) {
      maxs--;
    } else {
      s += vec[i];
    }
  }
  return s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = -1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans = max(ans, dfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
