MAX=100000
def Allocate(A, p, k, n):
    count=1
    s=0     
    index=0
    while index<n:
        if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
        if count>k:
            return False

    return True
         
    
n, k=map(int,input().split())
A=[int(input()) for i in range(n)]
left=0
right=MAX*MAX
while left+1<right:
    mid=left+(right-left)//2
    if Allocate(A,mid,k,n):
        right=mid
    else:
        left=mid
print(right) MAX=100000 MAX 100000 def Allocate(A, p, k, n):
    count=1
    s=0     
    index=0
    while index<n:
        if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
        if count>k:
            return False

    return True
         
     Allocate count=1 count 1 s=0 s 0 index=0 index 0 while index<n:
        if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
        if count>k:
            return False

     index<n index n if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
         s+A[index]<=p s+A[index] s A[index] A index p s+=A[index] s A[index] A index index+=1 index 1 count+=1 count 1 s=0 s 0 if count>k:
            return False

     count>k count k return False False return True True A A p p k k n n n, k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input A=[int(input()) for i in range(n)] A [int(input()) for i in range(n)] left=0 left 0 right=MAX*MAX right MAX*MAX MAX MAX while left+1<right:
    mid=left+(right-left)//2
    if Allocate(A,mid,k,n):
        right=mid
    else:
        left=mid left+1<right left+1 left 1 right mid=left+(right-left)//2 mid left+(right-left)//2 left (right-left)//2 right-left right left 2 if Allocate(A,mid,k,n):
        right=mid
    else:
        left=mid Allocate(A,mid,k,n) Allocate A mid k n right=mid right mid left=mid left mid print(right) print right n, k=map(int,input().split()) map(int,input().split()) n def Allocate(A, p, k, n):
    count=1
    s=0     
    index=0
    while index<n:
        if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
        if count>k:
            return False

    return True
         
     def Allocate(A, p, k, n):
    count=1
    s=0     
    index=0
    while index<n:
        if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
        if count>k:
            return False

    return True
         
     Allocate k=map(int,input().split()) map(int,input().split()) k right=mid mid right MAX=100000 100000 MAX left=mid mid left mid=left+(right-left)//2 left+(right-left)//2 mid A=[int(input()) for i in range(n)] [int(input()) for i in range(n)] A left=0 0 left right=MAX*MAX MAX*MAX right
MAX=100000
def Allocate(A, p, k, n):
    count=1
    s=0     
    index=0
    while index<n:
        if s+A[index]<=p:
            s+=A[index]
            index+=1
        else:
            count+=1
            s=0
        if count>k:
            return False

    return True
         
    
n, k=map(int,input().split())
A=[int(input()) for i in range(n)]
left=0
right=MAX*MAX
while left+1<right:
    mid=left+(right-left)//2
    if Allocate(A,mid,k,n):
        right=mid
    else:
        left=mid
print(right)
