import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N, K = MI()
W = [0] * N
for i in range(N):
    w = I()
    W[i] = w


def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    cnt = 0
    w_sum = 0
    for i in range(N):
        w_sum += W[i]
        if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
    if w_sum != 0:
        cnt += 1
    return cnt <= K


def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

a = max(W)
b = sum(W)
print(meguru_bisect(a - 1, b + 1)) import bisect, collections, copy, heapq, itertools, math, string bisect collections copy heapq itertools math string import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def MI(): return map(int, sys.stdin.readline().rstrip().split()) MI def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) LI def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split()) LS N, K = MI() N MI() MI K W = [0] * N W [0] * N [0] 0 N for i in range(N):
    w = I()
    W[i] = w i range(N) range N w = I() w I() I W[i] = w W[i] W i w def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    cnt = 0
    w_sum = 0
    for i in range(N):
        w_sum += W[i]
        if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
    if w_sum != 0:
        cnt += 1
    return cnt <= K is_ok cnt = 0 cnt 0 w_sum = 0 w_sum 0 for i in range(N):
        w_sum += W[i]
        if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
     i range(N) range N w_sum += W[i] w_sum W[i] W i if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
     w_sum > arg w_sum arg cnt += 1 cnt 1 w_sum = W[i] w_sum W[i] W i elif w_sum == arg:
            cnt += 1
            w_sum = 0
         w_sum == arg w_sum arg cnt += 1 cnt 1 w_sum = 0 w_sum 0 cnt += 0 cnt 0 if w_sum != 0:
        cnt += 1
     w_sum != 0 w_sum 0 cnt += 1 cnt 1 return cnt <= K cnt <= K cnt K arg arg def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok meguru_bisect '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    ''' while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
     abs(ok - ng) > 1 abs(ok - ng) abs ok - ng ok ng 1 mid = (ok + ng) // 2 mid (ok + ng) // 2 ok + ng ok ng 2 if is_ok(mid):
            ok = mid
        else:
            ng = mid
     is_ok(mid) is_ok mid ok = mid ok mid ng = mid ng mid return ok ok ng ng ok ok a = max(W) a max(W) max W b = sum(W) b sum(W) sum W print(meguru_bisect(a - 1, b + 1)) print meguru_bisect(a - 1, b + 1) meguru_bisect a - 1 a 1 b + 1 b 1 b = sum(W) sum(W) b def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    cnt = 0
    w_sum = 0
    for i in range(N):
        w_sum += W[i]
        if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
    if w_sum != 0:
        cnt += 1
    return cnt <= K def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    cnt = 0
    w_sum = 0
    for i in range(N):
        w_sum += W[i]
        if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
    if w_sum != 0:
        cnt += 1
    return cnt <= K is_ok def S(): return sys.stdin.readline().rstrip() def S(): return sys.stdin.readline().rstrip() S W = [0] * N [0] * N W def LS(): return list(sys.stdin.readline().rstrip().split()) def LS(): return list(sys.stdin.readline().rstrip().split()) LS K = MI() MI() K def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) LI N, K = MI() MI() N def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I w = I() I() w def MI(): return map(int, sys.stdin.readline().rstrip().split()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) MI a = max(W) max(W) a def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok meguru_bisect
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N, K = MI()
W = [0] * N
for i in range(N):
    w = I()
    W[i] = w


def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    cnt = 0
    w_sum = 0
    for i in range(N):
        w_sum += W[i]
        if w_sum > arg:
            cnt += 1
            w_sum = W[i]
        elif w_sum == arg:
            cnt += 1
            w_sum = 0
        else:
            cnt += 0
    if w_sum != 0:
        cnt += 1
    return cnt <= K


def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

a = max(W)
b = sum(W)
print(meguru_bisect(a - 1, b + 1))
