import sys
input = sys.stdin.readline


def is_loadable(pack: list, k: int, P: int):
    _tmp = 0
    counter = 1
    for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
    return True


n, k = [int(i) for i in input().strip().split()]
pack = [None] * n
for i in range(n):
    pack[i] = int(input())

right = sum(pack)
left = max(pack)

while left < right:
    mid = (left + right) // 2
    if is_loadable(pack, k, mid):
        right = mid
    else:
        left = mid + 1

print(left)
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def is_loadable(pack: list, k: int, P: int):
    _tmp = 0
    counter = 1
    for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
    return True is_loadable _tmp = 0 _tmp 0 counter = 1 counter 1 for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
     w pack if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
         _tmp + w > P _tmp + w _tmp w P _tmp = w _tmp w counter += 1 counter 1 _tmp += w _tmp w if counter > k or w > P:
            return False
     counter > k or w > P counter > k counter k w > P w P return False False return True True pack: list pack k: int k P: int P int(i) for i in input().strip().split() for i in input().strip().split() i input().strip().split() ().strip().split ().strip() ().strip () input strip split for i in input().strip().split() int(i) int i n, k = [int(i) for i in input().strip().split()] n [int(i) for i in input().strip().split()] k pack = [None] * n pack [None] * n [None] None n for i in range(n):
    pack[i] = int(input()) i range(n) range n pack[i] = int(input()) pack[i] pack i int(input()) int input() input right = sum(pack) right sum(pack) sum pack left = max(pack) left max(pack) max pack while left < right:
    mid = (left + right) // 2
    if is_loadable(pack, k, mid):
        right = mid
    else:
        left = mid + 1 left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if is_loadable(pack, k, mid):
        right = mid
    else:
        left = mid + 1 is_loadable(pack, k, mid) is_loadable pack k mid right = mid right mid left = mid + 1 left mid + 1 mid 1 print(left) print left pack = [None] * n [None] * n pack n, k = [int(i) for i in input().strip().split()] [int(i) for i in input().strip().split()] n left = mid + 1 mid + 1 left right = sum(pack) sum(pack) right def is_loadable(pack: list, k: int, P: int):
    _tmp = 0
    counter = 1
    for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
    return True def is_loadable(pack: list, k: int, P: int):
    _tmp = 0
    counter = 1
    for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
    return True is_loadable k = [int(i) for i in input().strip().split()] [int(i) for i in input().strip().split()] k left = max(pack) max(pack) left mid = (left + right) // 2 (left + right) // 2 mid right = mid mid right input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline


def is_loadable(pack: list, k: int, P: int):
    _tmp = 0
    counter = 1
    for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
    return True


n, k = [int(i) for i in input().strip().split()]
pack = [None] * n
for i in range(n):
    pack[i] = int(input())

right = sum(pack)
left = max(pack)

while left < right:
    mid = (left + right) // 2
    if is_loadable(pack, k, mid):
        right = mid
    else:
        left = mid + 1

print(left)

