import math

n, k = list(map(int, input().split()))

a = [int(eval(input())) for _ in [None]*n]



lb = max(a)

ub = lb * n



while True:

    mid = (ub+lb) // 2

    remain = k - 1

    cw = 0

    for w in a:

        cw += w

        if cw > mid:

            remain -= 1

            cw = w

        if remain < 0:

            break

    if remain < 0:

        if lb == mid:

            print((lb+1))

            break

        lb = mid

    else:

        if lb == mid:

            print(lb)

            break

        ub = mid
def solve():

    import sys

    n, k = list(map(int, input().split()))

    ws = tuple(map(int, sys.stdin))



    ok, ng = sum(ws), max(ws)-1



    while ok-ng > 1:

        mid = (ok+ng+1)//2

        current = 0

        count = 0

        for w in ws:

            if current + w > mid:

                current = w

                count += 1

            else:

                current += w

        if count < k:

            ok = mid

        else:

            ng = mid



    print(ok)





if __name__ == "__main__":

    solve()

import math

n, k = list(map(int, input().split()))
a = [int(eval(input())) for _ in [None] * n]
lb = max(a)
ub = lb * n
while True:
    mid = (ub + lb) // 2
    remain = k - 1
    cw = 0
    for w in a:
        cw += w
        if cw > mid:
            remain -= 1
            cw = w
        if remain < 0:
            break
    if remain < 0:
        if lb == mid:
            print((lb + 1))
            break
        lb = mid
    else:
        if lb == mid:
            print(lb)
            break
        ub = mid

def solve():
    import sys

    n, k = list(map(int, input().split()))
    ws = tuple(map(int, sys.stdin))
    ok, ng = sum(ws), max(ws) - 1
    while ok - ng > 1:
        mid = (ok + ng + 1) // 2
        current = 0
        count = 0
        for w in ws:
            if current + w > mid:
                current = w
                count += 1
            else:
                current += w
        if count < k:
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == "__main__":
    solve()

-import math +def solve(): +    import sys -n, k = list(map(int, input().split())) -a = [int(eval(input())) for _ in [None] * n] -lb = max(a) -ub = lb * n -while True: -    mid = (ub + lb) // 2 -    remain = k - 1 -    cw = 0 -    for w in a: -        cw += w -        if cw > mid: -            remain -= 1 -            cw = w -        if remain < 0: -            break -    if remain < 0: -        if lb == mid: -            print((lb + 1)) -            break -        lb = mid -    else: -        if lb == mid: -            print(lb) -            break -        ub = mid +    n, k = list(map(int, input().split())) +    ws = tuple(map(int, sys.stdin)) +    ok, ng = sum(ws), max(ws) - 1 +    while ok - ng > 1: +        mid = (ok + ng + 1) // 2 +        current = 0 +        count = 0 +        for w in ws: +            if current + w > mid: +                current = w +                count += 1 +            else: +                current += w +        if count < k: +            ok = mid +        else: +            ng = mid +    print(ok) + + +if __name__ == "__main__": +    solve()