import numpy as np N, M = map(int, input().split()) W = tuple(map(int, input().split())) MAX = 1_000_000 if M < 2: print(0) exit() def dp(last, non_last): for w in W[:-1]: new_last = np.full(M + 1, -MAX) new_last[1:] = np.maximum(last[:-1] + w, non_last[:-1]) new_non_last = np.maximum(last, non_last) last, non_last = new_last, new_non_last return last, non_last # dp[i] = iコの点を打ち終えている # 一番目の点を含む dp_last = np.full(M + 1, -MAX) dp_non_last = np.full(M + 1, -MAX) dp_last[1] = 0 dp_last, dp_non_last = dp(dp_last, dp_non_last) ans = max(dp_last[-1] + W[-1], dp_non_last[-1]) # 一番目の点を含まない dp_last = np.full(M + 1, -MAX) dp_non_last = np.full(M + 1, -MAX) dp_non_last[0] = 0 dp_last, dp_non_last = dp(dp_last, dp_non_last) ans = max(ans, dp_last[-1], dp_non_last[-1]) print(ans)