def ok(p,w,k):
    track= 1
    weight= 0
    flag= True
    for i in w:
        if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
    if track<=k and flag:
        return True
    else:
        return False
            

n,k= map(int, input().split())
w=[]
for i in range(n):
    w.append(int(input()))
    
l=0
h=10**11
while l+1 < h:
    p= (l+h)//2
    if ok(p,w,k):
        h= p
    else:
        l= p
print(h)
     def ok(p,w,k):
    track= 1
    weight= 0
    flag= True
    for i in w:
        if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
    if track<=k and flag:
        return True
    else:
        return False
             ok track= 1 track 1 weight= 0 weight 0 flag= True flag True for i in w:
        if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
     i w if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
     i > p i p flag=False flag False break elif weight+ i> p:
            weight= i
            track+= 1
         weight+ i> p weight+ i weight i p weight= i weight i track+= 1 track 1 weight+= i weight i if track<=k and flag:
        return True
    else:
        return False
             track<=k and flag track<=k track k flag return True True return False False p p w w k k n,k= map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w=[] w [] for i in range(n):
    w.append(int(input()))
     i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input l=0 l 0 h=10**11 h 10**11 10 11 while l+1 < h:
    p= (l+h)//2
    if ok(p,w,k):
        h= p
    else:
        l= p l+1 < h l+1 l 1 h p= (l+h)//2 p (l+h)//2 l+h l h 2 if ok(p,w,k):
        h= p
    else:
        l= p ok(p,w,k) ok p w k h= p h p l= p l p print(h) print h h=10**11 10**11 h p= (l+h)//2 (l+h)//2 p h= p p h w=[] [] w k= map(int, input().split()) map(int, input().split()) k n,k= map(int, input().split()) map(int, input().split()) n l=0 0 l def ok(p,w,k):
    track= 1
    weight= 0
    flag= True
    for i in w:
        if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
    if track<=k and flag:
        return True
    else:
        return False
             def ok(p,w,k):
    track= 1
    weight= 0
    flag= True
    for i in w:
        if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
    if track<=k and flag:
        return True
    else:
        return False
             ok l= p p l
def ok(p,w,k):
    track= 1
    weight= 0
    flag= True
    for i in w:
        if i > p:
            flag=False
            break
        elif weight+ i> p:
            weight= i
            track+= 1
        else:
            weight+= i
    if track<=k and flag:
        return True
    else:
        return False
            

n,k= map(int, input().split())
w=[]
for i in range(n):
    w.append(int(input()))
    
l=0
h=10**11
while l+1 < h:
    p= (l+h)//2
    if ok(p,w,k):
        h= p
    else:
        l= p
print(h)
    
