#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  int N,K,V[100];
  cin>>N>>K;
  for (int i(0);i<N;i++) cin>>V[i];
  ll ans(0);
  for (int i(0);i<=min(N,K);i++){//とる個数
    int suteru_cnt = min(i,K - i);
    for (int j(0);j<=i;j++){//とるうち左からとる個数
      vector <int> get;
      for (int k(0);k<j;k++) get.push_back(V[k]);
      for (int k(0);k<(i-j);k++) get.push_back(V[N-k-1]);
      sort(get.begin(),get.end());
      ll tmp(0);
      for (int k(0);k<i;k++){
        if (k<suteru_cnt && get[k]<0) continue; 
        tmp+=get[k];
      }
      ans = max(tmp,ans);
    }
  }
  cout << ans << endl;
  return 0;
}
