#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  long long ans = 0;
  for (int a = 0; a <= k; a++) {
    for (int b = 0; b <= k - a; b++) {
      if (a + b > n) continue;
      int d = k - a - b;
      long long sum = 0;
      vector<long long> s;
      for (int i = 0; i < a; i++) {
        sum += v[i];
        s.push_back(v[i]);
      }
      for (int j = n - b; j < n; j++) {
        sum += v[j];
        s.push_back(v[j]);
      }
      sort(s.begin(), s.end());
      for (int m = 0; m < d; m++) {
        if (m >= s.size()) break;
        if (s[m] > 0) break;
        sum -= s[m];
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
}
