def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True


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

ws = [int(input()) for _ in range(n)]
l, r, p = max(ws), sum(ws), 0

while l < r:
    p = (l + r) // 2
    if check_p(p):
        r = p
    else:
        l = p = p + 1

print(p) def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True check_p global k, ws ct, nt = 0, 1 ct 0 nt 1 for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
     w ws if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
     ct + w <= p ct + w ct w p ct += w ct w nt += 1 nt 1 if nt > k:
                return False
             nt > k nt k return False False ct = w ct w return True True p p n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input ws = [int(input()) for _ in range(n)] ws [int(input()) for _ in range(n)] l, r, p = max(ws), sum(ws), 0 l max(ws) max ws r sum(ws) sum ws p 0 while l < r:
    p = (l + r) // 2
    if check_p(p):
        r = p
    else:
        l = p = p + 1 l < r l r p = (l + r) // 2 p (l + r) // 2 l + r l r 2 if check_p(p):
        r = p
    else:
        l = p = p + 1 check_p(p) check_p p r = p r p l = p = p + 1 l p + 1 p 1 = p = p + 1 p p + 1 print(p) print p def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True check_p k = map(int, input().split()) map(int, input().split()) k r, p = max(ws), sum(ws), 0 sum(ws) r n, k = map(int, input().split()) map(int, input().split()) n l, r, p = max(ws), sum(ws), 0 max(ws) l p = (l + r) // 2 (l + r) // 2 p p = p + 1 p + 1 p p = max(ws), sum(ws), 0 0 p ws = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] ws r = p p r l = p = p + 1 p + 1 l
def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True


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

ws = [int(input()) for _ in range(n)]
l, r, p = max(ws), sum(ws), 0

while l < r:
    p = (l + r) // 2
    if check_p(p):
        r = p
    else:
        l = p = p + 1

print(p)