#coding:UTF-8
def Check(P,k,w):
    i=0
    for j in range(k):
        s=0
        while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
    return i

def Allocation(n,k,w):
    left=0
    right=100000000000000
    while right-left > 1:
        mid=int((left+right)/2)
        v=Check(mid,k,w)
        if v>=n:
            right=mid
        else:
            left=mid
    print(right)
  
if __name__=="__main__":
    a=input()
    n=int(a.split(" ")[0])
    k=int(a.split(" ")[1])
    w=[]
    for i in range(n):
        w.append(int(input()))
    Allocation(n,k,w) def Check(P,k,w):
    i=0
    for j in range(k):
        s=0
        while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
    return i Check i=0 i 0 for j in range(k):
        s=0
        while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
     j range(k) range k s=0 s 0 while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
     s+w[i]<=P s+w[i] s w[i] w i P s+=w[i] s w[i] w i i+=1 i 1 if i==n:
                return n
     i==n i n return n n return i i P P k k w w def Allocation(n,k,w):
    left=0
    right=100000000000000
    while right-left > 1:
        mid=int((left+right)/2)
        v=Check(mid,k,w)
        if v>=n:
            right=mid
        else:
            left=mid
    print(right)
   Allocation left=0 left 0 right=100000000000000 right 100000000000000 while right-left > 1:
        mid=int((left+right)/2)
        v=Check(mid,k,w)
        if v>=n:
            right=mid
        else:
            left=mid
     right-left > 1 right-left right left 1 mid=int((left+right)/2) mid int((left+right)/2) int (left+right)/2 left+right left right 2 v=Check(mid,k,w) v Check(mid,k,w) Check mid k w if v>=n:
            right=mid
        else:
            left=mid
     v>=n v n right=mid right mid left=mid left mid print(right) print right n n k k w w if __name__=="__main__":
    a=input()
    n=int(a.split(" ")[0])
    k=int(a.split(" ")[1])
    w=[]
    for i in range(n):
        w.append(int(input()))
    Allocation(n,k,w) __name__=="__main__" __name__ "__main__" a=input() a input() input n=int(a.split(" ")[0]) n int(a.split(" ")[0]) int a.split(" ")[0] a.split(" ") a.split a split " " 0 k=int(a.split(" ")[1]) k int(a.split(" ")[1]) int a.split(" ")[1] a.split(" ") a.split a split " " 1 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 Allocation(n,k,w) Allocation n k w w=[] [] w def Check(P,k,w):
    i=0
    for j in range(k):
        s=0
        while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
    return i def Check(P,k,w):
    i=0
    for j in range(k):
        s=0
        while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
    return i Check a=input() input() a k=int(a.split(" ")[1]) int(a.split(" ")[1]) k def Allocation(n,k,w):
    left=0
    right=100000000000000
    while right-left > 1:
        mid=int((left+right)/2)
        v=Check(mid,k,w)
        if v>=n:
            right=mid
        else:
            left=mid
    print(right)
   def Allocation(n,k,w):
    left=0
    right=100000000000000
    while right-left > 1:
        mid=int((left+right)/2)
        v=Check(mid,k,w)
        if v>=n:
            right=mid
        else:
            left=mid
    print(right)
   Allocation n=int(a.split(" ")[0]) int(a.split(" ")[0]) n
#coding:UTF-8
def Check(P,k,w):
    i=0
    for j in range(k):
        s=0
        while s+w[i]<=P:
            s+=w[i]
            i+=1
            if i==n:
                return n
    return i

def Allocation(n,k,w):
    left=0
    right=100000000000000
    while right-left > 1:
        mid=int((left+right)/2)
        v=Check(mid,k,w)
        if v>=n:
            right=mid
        else:
            left=mid
    print(right)
  
if __name__=="__main__":
    a=input()
    n=int(a.split(" ")[0])
    k=int(a.split(" ")[1])
    w=[]
    for i in range(n):
        w.append(int(input()))
    Allocation(n,k,w)