import sys input = sys.stdin.readline import bisect N,K=map(int,input().split()) A=list(map(int,input().split())) OK=0 NG=sum(A)//K+1 B=A*3 SUM=[0] for a in B: SUM.append(SUM[-1]+a) while NG-OK>1: mid=(OK+NG)//2 flag=0 for start in range(min(N//K+20,N%K+20)): if start>N: break G=0 now=start for j in range(K): now=bisect.bisect_left(SUM,SUM[now]+mid) if now>start+N: break if now<=start+N: flag=1 break if flag: OK=mid else: NG=mid print(OK)