n,m = map(int,raw_input().split()) if n <= 1 or m == 0: print 0 quit() w = map(int,raw_input().split()) def solve(start): dp = {(m-start,start):0} for i in xrange(n-1): tmp_dp = dict() for (k,h),v in dp.iteritems(): for nxt in xrange(2): if 0 <= k-nxt < n-1-i: nk = (k-nxt,nxt) nv = v + (w[i] if h*nxt == 1 else 0) if nk not in tmp_dp or tmp_dp[nk] < nv: tmp_dp[nk] = nv dp = tmp_dp return max(v + (w[n-1] if h*start else 0) for (k,h),v in dp.iteritems()) print max(solve(0), solve(1))