def check(k, p, w_list):
    i_w = 0
    for i_k in range(k):
        sum_w = 0
        while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
    return i_w

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

for _ in range(n):
    w = int(input())
    w_list.append(w)

left = 0
right = 100000 * 10000
mid = None

while left < right:
    mid = (left + right) // 2
    v = check(k, mid, w_list)
    if v >= n:
        right = mid
    else:
        left = mid + 1

print(right) def check(k, p, w_list):
    i_w = 0
    for i_k in range(k):
        sum_w = 0
        while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
    return i_w check i_w = 0 i_w 0 for i_k in range(k):
        sum_w = 0
        while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
     i_k range(k) range k sum_w = 0 sum_w 0 while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
     True if i_w >= len(w_list):
                return len(w_list)
             i_w >= len(w_list) i_w len(w_list) len w_list return len(w_list) len(w_list) len w_list if sum_w + w_list[i_w] > p:
                break
             sum_w + w_list[i_w] > p sum_w + w_list[i_w] sum_w w_list[i_w] w_list i_w p break sum_w += w_list[i_w] sum_w w_list[i_w] w_list i_w i_w += 1 i_w 1 return i_w i_w k k p p w_list w_list n, k = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k w_list = list() w_list list() list for _ in range(n):
    w = int(input())
    w_list.append(w) _ range(n) range n w = int(input()) w int(input()) int input() input w_list.append(w) w_list.append w_list append w left = 0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 mid = None mid None while left < right:
    mid = (left + right) // 2
    v = check(k, mid, w_list)
    if v >= n:
        right = mid
    else:
        left = mid + 1 left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 v = check(k, mid, w_list) v check(k, mid, w_list) check k mid w_list if v >= n:
        right = mid
    else:
        left = mid + 1 v >= n v n right = mid right mid left = mid + 1 left mid + 1 mid 1 print(right) print right k = list(map(int, input().split())) list(map(int, input().split())) k def check(k, p, w_list):
    i_w = 0
    for i_k in range(k):
        sum_w = 0
        while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
    return i_w def check(k, p, w_list):
    i_w = 0
    for i_k in range(k):
        sum_w = 0
        while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
    return i_w check v = check(k, mid, w_list) check(k, mid, w_list) v right = mid mid right mid = None None mid mid = (left + right) // 2 (left + right) // 2 mid right = 100000 * 10000 100000 * 10000 right n, k = list(map(int, input().split())) list(map(int, input().split())) n left = mid + 1 mid + 1 left w_list = list() list() w_list w = int(input()) int(input()) w left = 0 0 left
def check(k, p, w_list):
    i_w = 0
    for i_k in range(k):
        sum_w = 0
        while True:
            if i_w >= len(w_list):
                return len(w_list)
            if sum_w + w_list[i_w] > p:
                break
            sum_w += w_list[i_w]
            i_w += 1
    return i_w

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

for _ in range(n):
    w = int(input())
    w_list.append(w)

left = 0
right = 100000 * 10000
mid = None

while left < right:
    mid = (left + right) // 2
    v = check(k, mid, w_list)
    if v >= n:
        right = mid
    else:
        left = mid + 1

print(right)