def f(n, k, W):
    sum = 0
    i = 0
    while k > 0 and i < len(W):
        sum += W[i]
        if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
    if k == 0:
        return False
    else:
        return True


n ,k = [int(_) for _ in input().split()]
W = []
for i in range(n):
    W.append(int(input()))
low = 0
high = 10 ** 9
while low + 1 < high:
    mid = (low + high) // 2
    # print("mid", mid)
    # print("low", low)
    # print("high", high)
    # print("f", f(mid, k, W))
    # print("-----------------------")
    if f(mid, k, W):
        high = mid
    else:
        low = mid
print(high)
 def f(n, k, W):
    sum = 0
    i = 0
    while k > 0 and i < len(W):
        sum += W[i]
        if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
    if k == 0:
        return False
    else:
        return True f sum = 0 sum 0 i = 0 i 0 while k > 0 and i < len(W):
        sum += W[i]
        if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
     k > 0 and i < len(W) k > 0 k 0 i < len(W) i len(W) len W sum += W[i] sum W[i] W i if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
     sum <= n sum n i += 1 i 1 sum = 0 sum 0 k -= 1 k 1 if k == 0:
        return False
    else:
        return True k == 0 k 0 return False False return True True n n k k W W int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ n ,k = [int(_) for _ in input().split()] n [int(_) for _ in input().split()] k W = [] W [] for i in range(n):
    W.append(int(input())) i range(n) range n W.append(int(input())) W.append W append int(input()) int input() input low = 0 low 0 high = 10 ** 9 high 10 ** 9 10 9 while low + 1 < high:
    mid = (low + high) // 2
    # print("mid", mid)
    # print("low", low)
    # print("high", high)
    # print("f", f(mid, k, W))
    # print("-----------------------")
    if f(mid, k, W):
        high = mid
    else:
        low = mid low + 1 < high low + 1 low 1 high mid = (low + high) // 2 mid (low + high) // 2 low + high low high 2 if f(mid, k, W):
        high = mid
    else:
        low = mid f(mid, k, W) f mid k W high = mid high mid low = mid low mid print(high) print high high = 10 ** 9 10 ** 9 high def f(n, k, W):
    sum = 0
    i = 0
    while k > 0 and i < len(W):
        sum += W[i]
        if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
    if k == 0:
        return False
    else:
        return True def f(n, k, W):
    sum = 0
    i = 0
    while k > 0 and i < len(W):
        sum += W[i]
        if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
    if k == 0:
        return False
    else:
        return True f k = [int(_) for _ in input().split()] [int(_) for _ in input().split()] k low = mid mid low W = [] [] W n ,k = [int(_) for _ in input().split()] [int(_) for _ in input().split()] n mid = (low + high) // 2 (low + high) // 2 mid high = mid mid high low = 0 0 low
def f(n, k, W):
    sum = 0
    i = 0
    while k > 0 and i < len(W):
        sum += W[i]
        if sum <= n:
            i += 1
        else:
            sum = 0
            k -= 1
    if k == 0:
        return False
    else:
        return True


n ,k = [int(_) for _ in input().split()]
W = []
for i in range(n):
    W.append(int(input()))
low = 0
high = 10 ** 9
while low + 1 < high:
    mid = (low + high) // 2
    # print("mid", mid)
    # print("low", low)
    # print("high", high)
    # print("f", f(mid, k, W))
    # print("-----------------------")
    if f(mid, k, W):
        high = mid
    else:
        low = mid
print(high)

