const main = B => {
    const max = Math.max(...B)
    var ans = 0
    for(var i = (-1*max);i<=max;i++ ) {
        for(var n = 1;n<B.length;n++) {
            const C = B.slice(0,n).concat([i],B.slice(n,B.length))
            const tmp = C.reduce((acm,current) => {return acm + current},0)
            if(C[n] == Math.min(B[n-1],B[n]) && C[n+1] == Math.min(B[n+1],B[n+2])) {
                if(ans < tmp) {
                    ans = tmp
                }
            }
        }
    }            
    if(ans == 0) {
        return B.reduce((acm,current) => {return acm + current},0) + Math.min(...B)
    }else{
        return ans - Math.max(...B)
    }
}

const input = require('fs').readFileSync('/dev/stdin','utf8').split("\n")
const N = Number(input[0])
const B = input[1].split(" ").map(x => Number(x))
console.log(main(B))