import sys input = sys.stdin.readline N,K=map(int,input().split()) A=list(map(int,input().split())) if K==N-1: print(sum(A[1:])) exit() Ai = [(a,i) for i,a in enumerate(A)] B = sorted(Ai[1:], reverse=True) odd = [] even = [] ans = 0 for b,i in B[:K]: if i%2==0: odd.append((b,i)) else: even.append((b,i)) ans += b odd.sort(key=lambda x:x[1]) even.sort(key=lambda x:x[1]) if K==1: ans = max([A[i] for i in range(1,N,2)]) elif len(even)==0: base = ans # oddの先頭を取り除く b,i = odd[1] Ao = [A[j] for j in range(1,i,2)] mx = max(Ao) ans += mx - b # oddの先頭を生かす Ao = [A[j] for j in range(1,odd[0][1],2)] omin = min([o for o,i in odd]) ans = max(ans, base - omin + max(Ao)) elif len(odd)>0: if len(odd)==1: base = ans # oddを捨てる B = sorted([A[i] for i in range(1,N,2)], reverse=True) ans = sum(B[:K]) # oddを生かす emin = min([e for e,i in even]) B = [A[i] for i in range(1,odd[0][1],2)] ans = max(ans, base + max(B) - emin) elif odd[0][1]