#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(int i=m;i<n;i++)

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,0,n) cin>>a[i];
  ll ans=0;
  rep(i,1,min(n,k)+1){
    rep(j,0,i+1){
      ll cur=0;
      priority_queue<int,vector<int>,greater<int>> p;
      rep(l,0,j){
        p.push(a[l]);
        cur+=a[l];
      }
      rep(l,0,i-j){
        p.push(a[n-1-l]);
        cur+=a[n-1-l];
      }
      rep(l,0,k-i){
        int x=p.top();
        if(x<0) {
          cur-=x;
          p.pop();
        }
        else break;
        if(!p.size()) break;
      }
      ans=max(ans,cur);
    }
  }
  cout<<ans<<endl;
}