#include <bits/stdc++.h>
using namespace std;
int main() {
  long long 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 i = 0; i <= k; i++) {
    for (int m = 0; m <= min(i, (int)n); m++) {
      for (int j = 0; j <= m; j++) {
        vector<long long> have;
        for (int s = 0; s < j; s++) {
          have.push_back(v[s]);
        }
        for (int s = 0; s < m - j; s++) {
          have.push_back(v[n - 1 - s]);
        }
        sort((have).begin(), (have).end());
        reverse((have).begin(), (have).end());
        long long tmpsum = 0;
        for (int s = 0; s < min(have.size() - (i - m), have.size()); s++) {
          tmpsum += have[s];
        }
        ans = max(ans, tmpsum);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
