#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V;
  V.reserve(N);
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    V.push_back(v);
  }
  int max_ans = 0;
  for (int k = 0; k <= K; k++) {
    for (int i = 0; i <= K - k; i++) {
      int ans = 0;
      vector<int> tmp_v;
      for (int jl = 0; jl < i; jl++) {
        tmp_v.push_back(V[jl]);
      }
      for (int jr = 0; jr < (K - k) - i; jr++) {
        tmp_v.push_back(V[N - 1 - jr]);
      }
      sort(tmp_v.begin(), tmp_v.end());
      for (int x = k; x < tmp_v.size(); x++) {
        ans += tmp_v[x];
      }
      max_ans = max(max_ans, ans);
    }
  }
  cout << max_ans << endl;
  return 0;
}
