import sys

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

n, k = 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)