n,k = map(int,input().split()) a = list(map(int,input().split())) ans = 0 from collections import defaultdict import heapq d = defaultdict(int) sum_ = 0 q = [] for i,e in enumerate(sorted(set(a))): d[e] = i + 1 for i in range(n-1,0,-1): if i & 1: ans = max(ans ,a[i] + sum_) heapq.heappush(q,a[i]) else: heapq.heappush(q,a[i]) sum_ += a[i] if len(q) > k-1: sum_ -= heapq.heappop(q) print(ans)