def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))

    def check(P):
        s = 0
        res = 1
        for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
        return k>=res

    l,r = 0,1000000007
    m = 0
    while l<r-1:
        m = (l+r)//2
        if check(m):r = m
        else       :l = m
    print(r)



if __name__ == '__main__':
    main()

 def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))

    def check(P):
        s = 0
        res = 1
        for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
        return k>=res

    l,r = 0,1000000007
    m = 0
    while l<r-1:
        m = (l+r)//2
        if check(m):r = m
        else       :l = m
    print(r) main n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k a = [] a [] for _ in range(n):
        a.append(int(input()))

     _ range(n) range n a.append(int(input())) a.append a append int(input()) int input() input def check(P):
        s = 0
        res = 1
        for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
        return k>=res

     check s = 0 s 0 res = 1 res 1 for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
         b a if P<b:return False
             P<b P b if P<s+b:
                s = b
                res+=1
            else :s+=b
         P<s+b P s+b s b s = b s b res+=1 res 1 return k>=res k>=res k res P P l,r = 0,1000000007 l 0 r 1000000007 m = 0 m 0 while l<r-1:
        m = (l+r)//2
        if check(m):r = m
        else       :l = m
     l<r-1 l r-1 r 1 m = (l+r)//2 m (l+r)//2 l+r l r 2 if check(m):r = m
        else       :l = m
     check(m) check m print(r) print r if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))

    def check(P):
        s = 0
        res = 1
        for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
        return k>=res

    l,r = 0,1000000007
    m = 0
    while l<r-1:
        m = (l+r)//2
        if check(m):r = m
        else       :l = m
    print(r) def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))

    def check(P):
        s = 0
        res = 1
        for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
        return k>=res

    l,r = 0,1000000007
    m = 0
    while l<r-1:
        m = (l+r)//2
        if check(m):r = m
        else       :l = m
    print(r) main
def main():
    n,k = map(int,input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))

    def check(P):
        s = 0
        res = 1
        for b in a:
            if P<b:return False
            if P<s+b:
                s = b
                res+=1
            else :s+=b
        return k>=res

    l,r = 0,1000000007
    m = 0
    while l<r-1:
        m = (l+r)//2
        if check(m):r = m
        else       :l = m
    print(r)



if __name__ == '__main__':
    main()


