import math
from typing import List

buggage_num, truck_num = map(int, input().split())
buggage_list = [int(input()) for i in range(buggage_num)]


def able_to_load_buggage(max_weight: int,
                         truck_num: int, buggage_list: List[int]) -> bool:
    i = 0
    truck = [0 for i in range(truck_num + 1)]
    for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
    for t in truck:
        if t > max_weight:
            return False
    else:
        return True


# data = [i for i in range(31)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}')

left = 0
right = 100000 * 10000 + 1
i = 0
while left < right:
    i += 1
    mid = math.floor((left + right) / 2)
    result = able_to_load_buggage(mid, truck_num, buggage_list)
    # print(f'{i} {left} {mid} {right} {result}')
    if result:
        right = mid
    else:
        left = mid + 1
# print(f'{left} {mid} {right}')
print(left)
 import math math from typing import List buggage_num, truck_num = map(int, input().split()) buggage_num map(int, input().split()) map int input().split() ().split () input split truck_num int(input()) for i in range(buggage_num) for i in range(buggage_num) i range(buggage_num) range buggage_num for i in range(buggage_num) int(input()) int input() input buggage_list = [int(input()) for i in range(buggage_num)] buggage_list [int(input()) for i in range(buggage_num)] def able_to_load_buggage(max_weight: int,
                         truck_num: int, buggage_list: List[int]) -> bool:
    i = 0
    truck = [0 for i in range(truck_num + 1)]
    for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
    for t in truck:
        if t > max_weight:
            return False
    else:
        return True


# data = [i for i in range(31)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}') able_to_load_buggage i = 0 i 0 0 for i in range(truck_num + 1) for i in range(truck_num + 1) i range(truck_num + 1) range truck_num + 1 truck_num 1 for i in range(truck_num + 1) 0 truck = [0 for i in range(truck_num + 1)] truck [0 for i in range(truck_num + 1)] for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
     buggage buggage_list if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
         truck[i] + buggage <= max_weight truck[i] + buggage truck[i] truck i buggage max_weight truck[i] += buggage truck[i] truck i buggage i += 1 i 1 truck[i] += buggage truck[i] truck i buggage if i > (truck_num - 1):
            return False
     i > (truck_num - 1) i truck_num - 1 truck_num 1 return False False for t in truck:
        if t > max_weight:
            return False
    else:
        return True


# data = [i for i in range(31)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}') t truck if t > max_weight:
            return False
     t > max_weight t max_weight return False False return True True max_weight: int max_weight truck_num: int truck_num buggage_list: List[int] buggage_list left = 0 left 0 right = 100000 * 10000 + 1 right 100000 * 10000 + 1 100000 * 10000 100000 10000 1 i = 0 i 0 while left < right:
    i += 1
    mid = math.floor((left + right) / 2)
    result = able_to_load_buggage(mid, truck_num, buggage_list)
    # print(f'{i} {left} {mid} {right} {result}')
    if result:
        right = mid
    else:
        left = mid + 1
# print(f'{left} {mid} {right}') left < right left right i += 1 i 1 mid = math.floor((left + right) / 2) mid math.floor((left + right) / 2) math.floor math floor (left + right) / 2 left + right left right 2 result = able_to_load_buggage(mid, truck_num, buggage_list) result able_to_load_buggage(mid, truck_num, buggage_list) able_to_load_buggage mid truck_num buggage_list if result:
        right = mid
    else:
        left = mid + 1
# print(f'{left} {mid} {right}') result right = mid right mid left = mid + 1 left mid + 1 mid 1 print(left) print left def able_to_load_buggage(max_weight: int,
                         truck_num: int, buggage_list: List[int]) -> bool:
    i = 0
    truck = [0 for i in range(truck_num + 1)]
    for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
    for t in truck:
        if t > max_weight:
            return False
    else:
        return True


# data = [i for i in range(31)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}') def able_to_load_buggage(max_weight: int,
                         truck_num: int, buggage_list: List[int]) -> bool:
    i = 0
    truck = [0 for i in range(truck_num + 1)]
    for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
    for t in truck:
        if t > max_weight:
            return False
    else:
        return True


# data = [i for i in range(31)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}') able_to_load_buggage right = mid mid right i = 0 0 i left = mid + 1 mid + 1 left buggage_list = [int(input()) for i in range(buggage_num)] [int(input()) for i in range(buggage_num)] buggage_list mid = math.floor((left + right) / 2) math.floor((left + right) / 2) mid buggage_num, truck_num = map(int, input().split()) map(int, input().split()) buggage_num right = 100000 * 10000 + 1 100000 * 10000 + 1 right i += 1 1 i result = able_to_load_buggage(mid, truck_num, buggage_list) able_to_load_buggage(mid, truck_num, buggage_list) result truck_num = map(int, input().split()) map(int, input().split()) truck_num left = 0 0 left
import math
from typing import List

buggage_num, truck_num = map(int, input().split())
buggage_list = [int(input()) for i in range(buggage_num)]


def able_to_load_buggage(max_weight: int,
                         truck_num: int, buggage_list: List[int]) -> bool:
    i = 0
    truck = [0 for i in range(truck_num + 1)]
    for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
    for t in truck:
        if t > max_weight:
            return False
    else:
        return True


# data = [i for i in range(31)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}')

left = 0
right = 100000 * 10000 + 1
i = 0
while left < right:
    i += 1
    mid = math.floor((left + right) / 2)
    result = able_to_load_buggage(mid, truck_num, buggage_list)
    # print(f'{i} {left} {mid} {right} {result}')
    if result:
        right = mid
    else:
        left = mid + 1
# print(f'{left} {mid} {right}')
print(left)

