MIN = -10**6 n,m = map(int,raw_input().split()) w = map(int,raw_input().split()) if m==0:print 0;quit() if m==n:print sum(w);quit() def solve(s): dp = [[[MIN]*2 for i in xrange(m+2)] for i in xrange(n)] dp[0][s][s] = 0 for i in xrange(n-1): for j in xrange(max(s,i+m-s-n+1),min(i+s,m)+1): for k in xrange(2): if dp[i][j][k] == MIN:continue dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]) dp[i+1][j+1][1] = max(dp[i+1][j+1][1],dp[i][j][k]+w[i]*k) return max(dp[n-1][m][0],dp[n-1][m][1]+w[n-1]*s) print max(solve(0), solve(1))