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

w = [int(eval(input())) for i in range(n)]

l = max(w)

r = sum(w)



while l < r:

    m = (l + r) // 2

    stack = car = 0

    for i in w:

        stack += i

        if stack > m:

            stack = i

            car += 1

    if car < k:

        r = m

    else:

        l = m + 1

print(l)
import sys



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

w = [int(sys.stdin.readline()[:-1]) for i in range(n)]

l = max(w)

r = sum(w)



while l < r:

    m = (l + r) // 2

    stack = car = 0

    for i in w:

        stack += i

        if stack > m:

            stack = i

            car += 1

    if car < k:

        r = m

    else:

        l = m + 1

print(l)
n, k = list(map(int, input().split()))
w = [int(eval(input())) for i in range(n)]
l = max(w)
r = sum(w)
while l < r:
    m = (l + r) // 2
    stack = car = 0
    for i in w:
        stack += i
        if stack > m:
            stack = i
            car += 1
    if car < k:
        r = m
    else:
        l = m + 1
print(l)

import sys

n, k = list(map(int, input().split()))
w = [int(sys.stdin.readline()[:-1]) for i in range(n)]
l = max(w)
r = sum(w)
while l < r:
    m = (l + r) // 2
    stack = car = 0
    for i in w:
        stack += i
        if stack > m:
            stack = i
            car += 1
    if car < k:
        r = m
    else:
        l = m + 1
print(l)

+import sys + -w = [int(eval(input())) for i in range(n)] +w = [int(sys.stdin.readline()[:-1]) for i in range(n)]