import sys

def check_sekisairyo(p_min):
    p_now = 0
    k_now = 0
    for w in w_i:
        p_now += w
        if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
        if k_now == k and p_now != 0:
            return False
    return True

n, k = map(int, input().split())
w_i = [int(input()) for i in range(n)]
left, right, p_min = max(w_i), sum(w_i), 0
while left < right:
    p_min = (left + right) // 2
    if check_sekisairyo(p_min):
        right = p_min
    else:
        left = p_min = p_min + 1
print(p_min) import sys sys def check_sekisairyo(p_min):
    p_now = 0
    k_now = 0
    for w in w_i:
        p_now += w
        if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
        if k_now == k and p_now != 0:
            return False
    return True check_sekisairyo p_now = 0 p_now 0 k_now = 0 k_now 0 for w in w_i:
        p_now += w
        if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
        if k_now == k and p_now != 0:
            return False
     w w_i p_now += w p_now w if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
         p_now > p_min p_now p_min p_now = w p_now w k_now += 1 k_now 1 elif p_now == p_min:
            p_now = 0
            k_now += 1
         p_now == p_min p_now p_min p_now = 0 p_now 0 k_now += 1 k_now 1 if k_now == k and p_now != 0:
            return False
     k_now == k and p_now != 0 k_now == k k_now k p_now != 0 p_now 0 return False False return True True p_min p_min n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input w_i = [int(input()) for i in range(n)] w_i [int(input()) for i in range(n)] left, right, p_min = max(w_i), sum(w_i), 0 left max(w_i) max w_i right sum(w_i) sum w_i p_min 0 while left < right:
    p_min = (left + right) // 2
    if check_sekisairyo(p_min):
        right = p_min
    else:
        left = p_min = p_min + 1 left < right left right p_min = (left + right) // 2 p_min (left + right) // 2 left + right left right 2 if check_sekisairyo(p_min):
        right = p_min
    else:
        left = p_min = p_min + 1 check_sekisairyo(p_min) check_sekisairyo p_min right = p_min right p_min left = p_min = p_min + 1 left p_min + 1 p_min 1 = p_min = p_min + 1 p_min p_min + 1 print(p_min) print p_min p_min = p_min + 1 p_min + 1 p_min p_min = max(w_i), sum(w_i), 0 0 p_min left = p_min = p_min + 1 p_min + 1 left p_min = (left + right) // 2 (left + right) // 2 p_min left, right, p_min = max(w_i), sum(w_i), 0 max(w_i) left w_i = [int(input()) for i in range(n)] [int(input()) for i in range(n)] w_i right, p_min = max(w_i), sum(w_i), 0 sum(w_i) right right = p_min p_min right k = map(int, input().split()) map(int, input().split()) k def check_sekisairyo(p_min):
    p_now = 0
    k_now = 0
    for w in w_i:
        p_now += w
        if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
        if k_now == k and p_now != 0:
            return False
    return True def check_sekisairyo(p_min):
    p_now = 0
    k_now = 0
    for w in w_i:
        p_now += w
        if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
        if k_now == k and p_now != 0:
            return False
    return True check_sekisairyo n, k = map(int, input().split()) map(int, input().split()) n
import sys

def check_sekisairyo(p_min):
    p_now = 0
    k_now = 0
    for w in w_i:
        p_now += w
        if p_now > p_min:
            p_now = w
            k_now += 1
        elif p_now == p_min:
            p_now = 0
            k_now += 1
        if k_now == k and p_now != 0:
            return False
    return True

n, k = map(int, input().split())
w_i = [int(input()) for i in range(n)]
left, right, p_min = max(w_i), sum(w_i), 0
while left < right:
    p_min = (left + right) // 2
    if check_sekisairyo(p_min):
        right = p_min
    else:
        left = p_min = p_min + 1
print(p_min)