"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var n = o.a();
  var k = o.a();

  var v = o.l();

  var leftV;
  var rightV;

  var max = 0;
  for (var left = 0; left <= k; left++) {
    leftV = v.slice(0, left);
    for (var right = 0; right <= k - left; right++) {
      rightV = v.slice(Math.max(left, v.length - right), v.length);

      // console.log({leftV, rightV});
      var maxK = k - left - right;
      var curV = leftV.concat(rightV);
      curV.sort((a, b) => a - b);

      var value = 0;
      for (var i = 0; i < curV.length; i++) {
        if (i < maxK && curV[i] < 0) continue;
        value += curV[i];
      }
      // console.log({left, right, value})
      if (value > max) max = value;
    }
  }

  console.log(max);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));
