def solve(): from heapq import heapify, heappop, heappush N, M = map(int, input().split()) T = list(map(int, input().split())) H = [(0, i) for i in range(M)] heapify(H) for t in T: w, j = heappop(H) heappush(H, (t + w, j)) return max(t for t, _ in H) #================================================== print(solve())