

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var V = input[1].split(" ").map(i=>parseInt(i));
  var ans=0;
  var save=[];
  for(var i=0;i<Math.min(K+1,N+1);i++){
    var minus=[...save];
    if(i==0){
      rsub=0;
    }else{
      rsub+=V[i-1];
    }
    if(V[i-1]<0){
      minus.push(V[i-1]);
      minus.sort(function(a,b){return a-b});
    }
    var save = [...minus];
    for(var j=0;j<Math.min(K+1-i,N+1-i);j++){
      if(j==0){
        lsub=0;
      }else{
        lsub+=V[N-j];
      }
      if(V[N-j]<0){
        minus.push(V[N-j]);
        minus.sort(function(a,b){return a-b});
      }
      var asub=rsub+lsub;
      for(var k=0;k<Math.min(K-i-j,minus.length);k++){
        asub-=minus[k];
      }
      ans=Math.max(ans,asub);
    }
  }
  
  

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));