n,m = map(int,input().split()) w = list(map(int,input().split())) inf = -10 ** 8 dp1 = [[[inf] * 2 for _ in range(m+1)] for _ in range(n)] dp1[0][1][1] = 0 dp2 = [[[inf] * 2 for _ in range(m+1)] for _ in range(n)] dp2[0][0][0] = 0 for i in range(n-1): for j in range(m+1): dp1[i+1][j][0] = max(dp1[i][j][0],dp1[i][j][1]) dp2[i+1][j][0] = max(dp2[i][j][0],dp2[i][j][1]) if j > 0: dp1[i+1][j][1] = max(dp1[i][j-1][1] + w[i],dp1[i][j-1][0]) dp2[i+1][j][1] = max(dp2[i][j-1][1] + w[i],dp2[i][j-1][0]) dp1[-1][m][1] += w[-1] ans = max(dp1[-1][m][1],dp1[-1][m][0],dp2[-1][m][0],dp2[-1][m][1]) print(ans)