def check(p):
    i = 0
    for j in range(track):
        s = 0
        while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
    return False
    
def solve():
    left = max(A)
    right = sum(A)
    while (right - left > 1):
        mid = int((left + right) / 2)
        if check(mid):
            right = mid
        else :
            left = mid
    if check(left):
        return left
    else :
        return right

if __name__ == '__main__':
    budget, track = list(map(int, input().split()))
    A = []
    for n in range(budget):
        A.append(int(input()))     
    ans = solve()
    print(ans) def check(p):
    i = 0
    for j in range(track):
        s = 0
        while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
    return False
     check i = 0 i 0 for j in range(track):
        s = 0
        while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
     j range(track) range track s = 0 s 0 while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
     s + A[i] <= p s + A[i] s A[i] A i p s += A[i] s A[i] A i i += 1 i 1 if i == budget:
                return True
     i == budget i budget return True True return False False p p def solve():
    left = max(A)
    right = sum(A)
    while (right - left > 1):
        mid = int((left + right) / 2)
        if check(mid):
            right = mid
        else :
            left = mid
    if check(left):
        return left
    else :
        return right solve left = max(A) left max(A) max A right = sum(A) right sum(A) sum A while (right - left > 1):
        mid = int((left + right) / 2)
        if check(mid):
            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 if check(mid):
            right = mid
        else :
            left = mid
     check(mid) check mid right = mid right mid left = mid left mid if check(left):
        return left
    else :
        return right check(left) check left return left left return right right if __name__ == '__main__':
    budget, track = list(map(int, input().split()))
    A = []
    for n in range(budget):
        A.append(int(input()))     
    ans = solve()
    print(ans) __name__ == '__main__' __name__ '__main__' budget, track = list(map(int, input().split())) budget list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split track A = [] A [] for n in range(budget):
        A.append(int(input()))     
     n range(budget) range budget A.append(int(input())) A.append A append int(input()) int input() input ans = solve() ans solve() solve print(ans) print ans track = list(map(int, input().split())) list(map(int, input().split())) track budget, track = list(map(int, input().split())) list(map(int, input().split())) budget def solve():
    left = max(A)
    right = sum(A)
    while (right - left > 1):
        mid = int((left + right) / 2)
        if check(mid):
            right = mid
        else :
            left = mid
    if check(left):
        return left
    else :
        return right def solve():
    left = max(A)
    right = sum(A)
    while (right - left > 1):
        mid = int((left + right) / 2)
        if check(mid):
            right = mid
        else :
            left = mid
    if check(left):
        return left
    else :
        return right solve A = [] [] A def check(p):
    i = 0
    for j in range(track):
        s = 0
        while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
    return False
     def check(p):
    i = 0
    for j in range(track):
        s = 0
        while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
    return False
     check ans = solve() solve() ans
def check(p):
    i = 0
    for j in range(track):
        s = 0
        while s + A[i] <= p:
            s += A[i]
            i += 1
            if i == budget:
                return True
    return False
    
def solve():
    left = max(A)
    right = sum(A)
    while (right - left > 1):
        mid = int((left + right) / 2)
        if check(mid):
            right = mid
        else :
            left = mid
    if check(left):
        return left
    else :
        return right

if __name__ == '__main__':
    budget, track = list(map(int, input().split()))
    A = []
    for n in range(budget):
        A.append(int(input()))     
    ans = solve()
    print(ans)
