n,k=map(int,input().split())
A=[int(input()) for i in range(n)]

def track_num(n):
    cnt,track=0,1
    for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
    return track

def Binaryserch():
    left,right=max(A),sum(A)+1
    ans=0
    while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
    return ans

print(Binaryserch())
 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)] def track_num(n):
    cnt,track=0,1
    for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
    return track track_num cnt,track=0,1 cnt 0 track 1 for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
     i A if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
     cnt+i>n cnt+i cnt i n track +=1 track 1 cnt=i cnt i cnt +=i cnt i return track track n n def Binaryserch():
    left,right=max(A),sum(A)+1
    ans=0
    while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
    return ans Binaryserch left,right=max(A),sum(A)+1 left max(A) max A right sum(A)+1 sum(A) sum A 1 ans=0 ans 0 while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
     left<right left right mid=(left+right)//2 mid (left+right)//2 left+right left right 2 track=track_num(mid) track track_num(mid) track_num mid if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
     track<=k track k ans=mid ans mid right=mid right mid elif track>k:
            left=mid+1
     track>k track k left=mid+1 left mid+1 mid 1 return ans ans print(Binaryserch()) print Binaryserch() Binaryserch k=map(int,input().split()) map(int,input().split()) k n,k=map(int,input().split()) map(int,input().split()) n def track_num(n):
    cnt,track=0,1
    for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
    return track def track_num(n):
    cnt,track=0,1
    for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
    return track track_num A=[int(input()) for i in range(n)] [int(input()) for i in range(n)] A def Binaryserch():
    left,right=max(A),sum(A)+1
    ans=0
    while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
    return ans def Binaryserch():
    left,right=max(A),sum(A)+1
    ans=0
    while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
    return ans Binaryserch
n,k=map(int,input().split())
A=[int(input()) for i in range(n)]

def track_num(n):
    cnt,track=0,1
    for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
    return track

def Binaryserch():
    left,right=max(A),sum(A)+1
    ans=0
    while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
    return ans

print(Binaryserch())

