"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const V = arg[1].split(" ").map(n=>parseInt(n));
    
    let answerList = [0];
    
    for(let a=0; a<=Math.min(K, N); a++) {
        for(let b=0; b<=Math.min(K, N); b++) {
            const rest = K - (a + b);
            
            if(N < a + b) continue;
            if(rest < 0) continue;
            
            let list = [];
            
            list = [...V.slice(0, a), ...V.slice(V.length - b, V.length)];

            list.sort((a,b)=>a-b);
            
            let deleteCnt = 0;
            
            for(let i=0; i<rest; i++) {
                if(list[i] < 0) {
                    deleteCnt++;
                } else {
                    break;
                }
            }
            
            list.splice(0, deleteCnt);
            
            if(list.length) {
                answerList.push(list.reduce((m,n)=>m+n));
            }
        }
    }
    
    const answer = answerList.sort((a,b)=>b-a)[0];
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));