import sys
readline=sys.stdin.readline

def Bisect_Int(ok,ng,is_ok):
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if is_ok(mid):
            ok=mid
        else:
            ng=mid
    return ok

N,K=map(int,readline().split())
A=list(map(int,readline().split()))
sum_A=sum(A)
A=[0]+A*2
for i in range(1,2*N+1):
    A[i]+=A[i-1]
def is_ok(ans):
    perm=[i for i in range(2*N+1)]
    r=0
    for l in range(2*N):
        while r<2*N and A[r]-A[l]<ans:
            r+=1
        perm[l]=r
    k=K.bit_length()
    perm_doub=[[perm[n]] for n in range(2*N+1)]
    for kk in range(1,k):
        for n in range(2*N+1):
            perm_doub[n].append(perm_doub[perm_doub[n][kk-1]][kk-1])
    for i in range(N):
        x=i
        for kk in range(k):
            if K>>kk&1:
                x=perm_doub[x][kk]
        if ans<A[i]:
            break
        if x<=i+N:
            return True
    return False
ans=Bisect_Int(0,sum_A//K+1,is_ok)
print(ans)