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