def ok(a, n, k, p):
    t = 0
    t_cnt = 0
    for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
    return 0


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

P_max = n * 10000 // k + 10001

l = 0
r = P_max
m = 0
while l < r - 1:
    m = (l + r) // 2
    if ok(a, n, k, m) == 0:
        r = m
    else:
        l = m

print(r)







 def ok(a, n, k, p):
    t = 0
    t_cnt = 0
    for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
    return 0 ok t = 0 t 0 t_cnt = 0 t_cnt 0 for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
     w a if p < w:
            return -1
         p < w p w return -1 -1 if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
     t + w > p t + w t w p t_cnt += 1 t_cnt 1 if t_cnt >= k:
                return -1
             t_cnt >= k t_cnt k return -1 -1 t = w t w t += w t w return 0 0 a a n n k k 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 a = [int(input()) for _ in range(n)] a [int(input()) for _ in range(n)] P_max = n * 10000 // k + 10001 P_max n * 10000 // k + 10001 n * 10000 // k n * 10000 n 10000 k 10001 l = 0 l 0 r = P_max r P_max m = 0 m 0 while l < r - 1:
    m = (l + r) // 2
    if ok(a, n, k, m) == 0:
        r = m
    else:
        l = m l < r - 1 l r - 1 r 1 m = (l + r) // 2 m (l + r) // 2 l + r l r 2 if ok(a, n, k, m) == 0:
        r = m
    else:
        l = m ok(a, n, k, m) == 0 ok(a, n, k, m) ok a n k m 0 r = m r m l = m l m print(r) print r m = (l + r) // 2 (l + r) // 2 m a = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] a P_max = n * 10000 // k + 10001 n * 10000 // k + 10001 P_max l = m m l n, k = map(int, input().split()) map(int, input().split()) n r = m m r l = 0 0 l r = P_max P_max r m = 0 0 m k = map(int, input().split()) map(int, input().split()) k def ok(a, n, k, p):
    t = 0
    t_cnt = 0
    for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
    return 0 def ok(a, n, k, p):
    t = 0
    t_cnt = 0
    for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
    return 0 ok
def ok(a, n, k, p):
    t = 0
    t_cnt = 0
    for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
    return 0


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

P_max = n * 10000 // k + 10001

l = 0
r = P_max
m = 0
while l < r - 1:
    m = (l + r) // 2
    if ok(a, n, k, m) == 0:
        r = m
    else:
        l = m

print(r)








