def check(w_list, k, P):
    tmp = 0
    tmp_k = 1
    if max(w_list) > P:
        return False
    for w in w_list:
        tmp += w
        if tmp > P:
            tmp_k += 1
            tmp = w
    if tmp_k <= k:
        return True
    else:
        return False


def binary_search(w_list, k, l, r):
    while(r - l > 1):
        c = (l + r) // 2
        # print(c)
        # print(check(w_list, k, c))
        if check(w_list, k, c):
            r = c
        else:
            l = c

    return r


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

max_P = n * 10000

min_P = binary_search(w_list, k, 0, max_P)

print(min_P)
 def check(w_list, k, P):
    tmp = 0
    tmp_k = 1
    if max(w_list) > P:
        return False
    for w in w_list:
        tmp += w
        if tmp > P:
            tmp_k += 1
            tmp = w
    if tmp_k <= k:
        return True
    else:
        return False check tmp = 0 tmp 0 tmp_k = 1 tmp_k 1 if max(w_list) > P:
        return False
     max(w_list) > P max(w_list) max w_list P return False False for w in w_list:
        tmp += w
        if tmp > P:
            tmp_k += 1
            tmp = w
     w w_list tmp += w tmp w if tmp > P:
            tmp_k += 1
            tmp = w
     tmp > P tmp P tmp_k += 1 tmp_k 1 tmp = w tmp w if tmp_k <= k:
        return True
    else:
        return False tmp_k <= k tmp_k k return True True return False False w_list w_list k k P P def binary_search(w_list, k, l, r):
    while(r - l > 1):
        c = (l + r) // 2
        # print(c)
        # print(check(w_list, k, c))
        if check(w_list, k, c):
            r = c
        else:
            l = c

    return r binary_search while(r - l > 1):
        c = (l + r) // 2
        # print(c)
        # print(check(w_list, k, c))
        if check(w_list, k, c):
            r = c
        else:
            l = c

     r - l > 1 r - l r l 1 c = (l + r) // 2 c (l + r) // 2 l + r l r 2 if check(w_list, k, c):
            r = c
        else:
            l = c

     check(w_list, k, c) check w_list k c r = c r c l = c l c return r r w_list w_list k k l l r r n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w_list = [] w_list [] for _ in range(n):
    w_list.append(int(input())) _ range(n) range n w_list.append(int(input())) w_list.append w_list append int(input()) int input() input max_P = n * 10000 max_P n * 10000 n 10000 min_P = binary_search(w_list, k, 0, max_P) min_P binary_search(w_list, k, 0, max_P) binary_search w_list k 0 max_P print(min_P) print min_P max_P = n * 10000 n * 10000 max_P def binary_search(w_list, k, l, r):
    while(r - l > 1):
        c = (l + r) // 2
        # print(c)
        # print(check(w_list, k, c))
        if check(w_list, k, c):
            r = c
        else:
            l = c

    return r def binary_search(w_list, k, l, r):
    while(r - l > 1):
        c = (l + r) // 2
        # print(c)
        # print(check(w_list, k, c))
        if check(w_list, k, c):
            r = c
        else:
            l = c

    return r binary_search min_P = binary_search(w_list, k, 0, max_P) binary_search(w_list, k, 0, max_P) min_P k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n def check(w_list, k, P):
    tmp = 0
    tmp_k = 1
    if max(w_list) > P:
        return False
    for w in w_list:
        tmp += w
        if tmp > P:
            tmp_k += 1
            tmp = w
    if tmp_k <= k:
        return True
    else:
        return False def check(w_list, k, P):
    tmp = 0
    tmp_k = 1
    if max(w_list) > P:
        return False
    for w in w_list:
        tmp += w
        if tmp > P:
            tmp_k += 1
            tmp = w
    if tmp_k <= k:
        return True
    else:
        return False check w_list = [] [] w_list
def check(w_list, k, P):
    tmp = 0
    tmp_k = 1
    if max(w_list) > P:
        return False
    for w in w_list:
        tmp += w
        if tmp > P:
            tmp_k += 1
            tmp = w
    if tmp_k <= k:
        return True
    else:
        return False


def binary_search(w_list, k, l, r):
    while(r - l > 1):
        c = (l + r) // 2
        # print(c)
        # print(check(w_list, k, c))
        if check(w_list, k, c):
            r = c
        else:
            l = c

    return r


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

max_P = n * 10000

min_P = binary_search(w_list, k, 0, max_P)

print(min_P)

