function main(input) {
  var input=input.trim().split("\n");
  var N = Number(input[0].split(" ")[0]);
  var K = Number(input[0].split(" ")[1]);
  var items = input[1].split(" ").map(v=>Number(v));
  var leftSums = [], rightSums=[];
  var leftMinus = [], rightMinus=[];
  for(var i=0;i<N;i++){
    leftSums[i] = items[i] + (leftSums[i-1]||0);
    rightSums[i] = items[N-i-1] + (rightSums[i-1]||0);
    if(!leftMinus[i-1]) leftMinus[i]=[];
    else leftMinus[i] = leftMinus[i-1].concat();
    if(items[i]<0){
      leftMinus[i].push(items[i]);
    }
    if(!rightMinus[i-1]) rightMinus[i]=[];
    else rightMinus[i] = rightMinus[i-1].concat();
    if(items[N-i-1]<0){
      rightMinus[i].push(items[N-i-1]);
    }
  }
  var ans = 0;
  for(var n=0;n<=K;n++){
    for(var i=0;i<=n&&i<=N;i++){
      for(var j=0;j<=n-i&&j<=N-i;j++){
        var leftsum = leftSums[i-1]||0;
        var rightsum = rightSums[j-1]||0;
        var minusItems = (leftMinus[i-1]||[]).concat((rightMinus[j-1]||[]));
        var sum = leftsum+rightsum;
        if(n>i+j){
          minusItems.sort((a,b)=>a-b);
          for(var k=0;k<=n-i-j&&k<minusItems.length;k++){
            sum -= minusItems[k-1]||0;
          }
        }
        ans = Math.max(ans, sum);
      }
    }
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
