import sys

readline = sys.stdin.readline

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

v = tuple(int(readline()) for _ in range(n))

lo = max(v) - 1

hi = int(1e10)

while hi - lo > 1:

    p = P = (lo + hi) // 2

    m = 1

    for i in range(n):

        if v[i] > p:

            p = P

            m += 1

        p -= v[i]

    if m <= k:

        hi = P

    else:

        lo = P

print(hi)



import sys

readline = sys.stdin.readline

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

v = [int(readline()) for _ in range(n)]

lo = max(v) - 1

hi = sum(v)

while hi - lo > 1:

    p = P = (lo + hi) // 2

    m = 1

    for i in range(n):

        if v[i] > p:

            p = P

            m += 1

        p -= v[i]

    if m <= k:

        hi = P

    else:

        lo = P

print(hi)



import sys

readline = sys.stdin.readline
n, k = list(map(int, input().split()))
v = tuple(int(readline()) for _ in range(n))
lo = max(v) - 1
hi = int(1e10)
while hi - lo > 1:
    p = P = (lo + hi) // 2
    m = 1
    for i in range(n):
        if v[i] > p:
            p = P
            m += 1
        p -= v[i]
    if m <= k:
        hi = P
    else:
        lo = P
print(hi)

import sys

readline = sys.stdin.readline
n, k = list(map(int, readline().split()))
v = [int(readline()) for _ in range(n)]
lo = max(v) - 1
hi = sum(v)
while hi - lo > 1:
    p = P = (lo + hi) // 2
    m = 1
    for i in range(n):
        if v[i] > p:
            p = P
            m += 1
        p -= v[i]
    if m <= k:
        hi = P
    else:
        lo = P
print(hi)

-n, k = list(map(int, input().split())) -v = tuple(int(readline()) for _ in range(n)) +n, k = list(map(int, readline().split())) +v = [int(readline()) for _ in range(n)] -hi = int(1e10) +hi = sum(v)