def Is_ToPut(p,w,k):
    count =1
    temp =p
    for i in w:
        if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
    if count <= k:return 1
    else:return 0

n,k = list(map(int,input().split(' ')))
w =[]
for _ in range(n):
    w.append(int(input()))
ans =100000*10000
left = 0
right = 100000*10000
while left < right:
    p = (left+right)//2
    if Is_ToPut(p,w,k):
        if ans > p:ans =p
        right=p
    else:
        left = p +1
print(ans)
         def Is_ToPut(p,w,k):
    count =1
    temp =p
    for i in w:
        if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
    if count <= k:return 1
    else:return 0 Is_ToPut count =1 count 1 temp =p temp p for i in w:
        if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
     i w if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
     temp >= i temp i temp -=i temp i elif i > p :
            return 0
         i > p i p return 0 0 count +=1 count 1 temp =p-i temp p-i p i if count <= k:return 1
    else:return 0 count <= k count k p p w w k k n,k = list(map(int,input().split(' '))) n list(map(int,input().split(' '))) list map(int,input().split(' ')) map int input().split(' ') ().split () input split ' ' k w =[] w [] for _ in range(n):
    w.append(int(input())) _ range(n) range n w.append(int(input())) w.append w append int(input()) int input() input ans =100000*10000 ans 100000*10000 100000 10000 left = 0 left 0 right = 100000*10000 right 100000*10000 100000 10000 while left < right:
    p = (left+right)//2
    if Is_ToPut(p,w,k):
        if ans > p:ans =p
        right=p
    else:
        left = p +1 left < right left right p = (left+right)//2 p (left+right)//2 left+right left right 2 if Is_ToPut(p,w,k):
        if ans > p:ans =p
        right=p
    else:
        left = p +1 Is_ToPut(p,w,k) Is_ToPut p w k if ans > p:ans =p
         ans > p ans p right=p right p left = p +1 left p +1 p 1 print(ans) print ans w =[] [] w left = 0 0 left right = 100000*10000 100000*10000 right n,k = list(map(int,input().split(' '))) list(map(int,input().split(' '))) n ans =100000*10000 100000*10000 ans def Is_ToPut(p,w,k):
    count =1
    temp =p
    for i in w:
        if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
    if count <= k:return 1
    else:return 0 def Is_ToPut(p,w,k):
    count =1
    temp =p
    for i in w:
        if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
    if count <= k:return 1
    else:return 0 Is_ToPut left = p +1 p +1 left p = (left+right)//2 (left+right)//2 p right=p p right k = list(map(int,input().split(' '))) list(map(int,input().split(' '))) k
def Is_ToPut(p,w,k):
    count =1
    temp =p
    for i in w:
        if temp >= i:
            temp -=i
        elif i > p :
            return 0
        else:     
            count +=1
            temp =p-i
    if count <= k:return 1
    else:return 0

n,k = list(map(int,input().split(' ')))
w =[]
for _ in range(n):
    w.append(int(input()))
ans =100000*10000
left = 0
right = 100000*10000
while left < right:
    p = (left+right)//2
    if Is_ToPut(p,w,k):
        if ans > p:ans =p
        right=p
    else:
        left = p +1
print(ans)
        
