n,m=map(int,input().split()) t=list(map(int,input().split())) from heapq import heappush,heappop q=[0]*m for v in t: u=heappop(q) heappush(q,u+v) print(max(q))