
def countPakages(P, k, W):
    i, n = 0, len(W)
    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 ALDS1_4D():
    n_limit, k_limit, wi_limit = 100000, 100000, 10000
    n, k= map(int, input().split())
    W = [int(input()) for i in range(n)]
    Pleft, Pright = 0, n_limit * wi_limit
    while Pright - Pleft > 1:
        Pmid = (Pleft+Pright)//2
        v = countPakages(Pmid, k, W)
        if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

    return Pright
if __name__ == '__main__':
    print(ALDS1_4D()) def countPakages(P, k, W):
    i, n = 0, len(W)
    for j in range(k):
        s = 0
        while s + W[i] <=P:
            s += W[i]
            i += 1
            if i == n:
                return n
    return i countPakages i, n = 0, len(W) i 0 n len(W) len W 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 ALDS1_4D():
    n_limit, k_limit, wi_limit = 100000, 100000, 10000
    n, k= map(int, input().split())
    W = [int(input()) for i in range(n)]
    Pleft, Pright = 0, n_limit * wi_limit
    while Pright - Pleft > 1:
        Pmid = (Pleft+Pright)//2
        v = countPakages(Pmid, k, W)
        if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

    return Pright ALDS1_4D n_limit, k_limit, wi_limit = 100000, 100000, 10000 n_limit 100000 k_limit 100000 wi_limit 10000 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 W = [int(input()) for i in range(n)] W [int(input()) for i in range(n)] Pleft, Pright = 0, n_limit * wi_limit Pleft 0 Pright n_limit * wi_limit n_limit wi_limit while Pright - Pleft > 1:
        Pmid = (Pleft+Pright)//2
        v = countPakages(Pmid, k, W)
        if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

     Pright - Pleft > 1 Pright - Pleft Pright Pleft 1 Pmid = (Pleft+Pright)//2 Pmid (Pleft+Pright)//2 Pleft+Pright Pleft Pright 2 v = countPakages(Pmid, k, W) v countPakages(Pmid, k, W) countPakages Pmid k W if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

     v < n v n Pleft = Pmid Pleft Pmid Pright = Pmid Pright Pmid return Pright Pright if __name__ == '__main__':
    print(ALDS1_4D()) __name__ == '__main__' __name__ '__main__' print(ALDS1_4D()) print ALDS1_4D() ALDS1_4D def ALDS1_4D():
    n_limit, k_limit, wi_limit = 100000, 100000, 10000
    n, k= map(int, input().split())
    W = [int(input()) for i in range(n)]
    Pleft, Pright = 0, n_limit * wi_limit
    while Pright - Pleft > 1:
        Pmid = (Pleft+Pright)//2
        v = countPakages(Pmid, k, W)
        if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

    return Pright def ALDS1_4D():
    n_limit, k_limit, wi_limit = 100000, 100000, 10000
    n, k= map(int, input().split())
    W = [int(input()) for i in range(n)]
    Pleft, Pright = 0, n_limit * wi_limit
    while Pright - Pleft > 1:
        Pmid = (Pleft+Pright)//2
        v = countPakages(Pmid, k, W)
        if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

    return Pright ALDS1_4D def countPakages(P, k, W):
    i, n = 0, len(W)
    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 countPakages(P, k, W):
    i, n = 0, len(W)
    for j in range(k):
        s = 0
        while s + W[i] <=P:
            s += W[i]
            i += 1
            if i == n:
                return n
    return i countPakages

def countPakages(P, k, W):
    i, n = 0, len(W)
    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 ALDS1_4D():
    n_limit, k_limit, wi_limit = 100000, 100000, 10000
    n, k= map(int, input().split())
    W = [int(input()) for i in range(n)]
    Pleft, Pright = 0, n_limit * wi_limit
    while Pright - Pleft > 1:
        Pmid = (Pleft+Pright)//2
        v = countPakages(Pmid, k, W)
        if v < n:
            Pleft = Pmid
        else:
            Pright = Pmid

    return Pright
if __name__ == '__main__':
    print(ALDS1_4D())