N, M = map(int, input().split()) W = list(map(int, input().split())) inf = 10 ** 18 pre = [[-inf] * 2 for i in range(N + 1)] pre[0][0] = 0 for i in range(1, N): dp = [[-inf] * 2 for i in range(N + 1)] for j in range(N + 1): dp[j][0] = max(dp[j][0], pre[j][0], pre[j][1]) if j: dp[j][1] = max(dp[j][1], pre[j - 1][1] + W[i - 1], pre[j - 1][0]) dp, pre = pre, dp ans = max(pre[M]) pre = [[-inf] * 2 for i in range(N + 1)] pre[1][1] = 0 for i in range(1, N): dp = [[-inf] * 2 for i in range(N + 1)] for j in range(N + 1): dp[j][0] = max(dp[j][0], pre[j][0], pre[j][1]) if j: dp[j][1] = max(dp[j][1], pre[j - 1][1] + W[i - 1], pre[j - 1][0]) dp, pre = pre, dp ans = max(ans, pre[M][0], pre[M][1] + W[-1]) print(ans)