def min_item_num(weights, num_item, num_vehicle, capacity):
    item_idx = 0
    for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
    return item_idx


def main():
    num_item, num_vehicle = list(map(int, input().split(" ")))
    weights = [int(input()) for _ in range(num_item)]
    left = 0
    right = 10000 * 100000
    while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
    print(right)


if __name__ == "__main__":
    main()
 def min_item_num(weights, num_item, num_vehicle, capacity):
    item_idx = 0
    for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
    return item_idx min_item_num item_idx = 0 item_idx 0 for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
     _ range(num_vehicle) range num_vehicle load = 0 load 0 while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
     load + weights[item_idx] <= capacity load + weights[item_idx] load weights[item_idx] weights item_idx capacity load += weights[item_idx] load weights[item_idx] weights item_idx item_idx += 1 item_idx 1 if item_idx == num_item:
                return num_item
     item_idx == num_item item_idx num_item return num_item num_item return item_idx item_idx weights weights num_item num_item num_vehicle num_vehicle capacity capacity def main():
    num_item, num_vehicle = list(map(int, input().split(" ")))
    weights = [int(input()) for _ in range(num_item)]
    left = 0
    right = 10000 * 100000
    while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
    print(right) main num_item, num_vehicle = list(map(int, input().split(" "))) num_item list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " num_vehicle int(input()) for _ in range(num_item) for _ in range(num_item) _ range(num_item) range num_item for _ in range(num_item) int(input()) int input() input weights = [int(input()) for _ in range(num_item)] weights [int(input()) for _ in range(num_item)] left = 0 left 0 right = 10000 * 100000 right 10000 * 100000 10000 100000 while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
     right - left > 1 right - left right left 1 center = (left + right) // 2 center (left + right) // 2 left + right left right 2 min_item = min_item_num(weights, num_item, num_vehicle, center) min_item min_item_num(weights, num_item, num_vehicle, center) min_item_num weights num_item num_vehicle center if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
     num_item <= min_item num_item min_item right = center right center left = center left center print(right) print right if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def min_item_num(weights, num_item, num_vehicle, capacity):
    item_idx = 0
    for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
    return item_idx def min_item_num(weights, num_item, num_vehicle, capacity):
    item_idx = 0
    for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
    return item_idx min_item_num def main():
    num_item, num_vehicle = list(map(int, input().split(" ")))
    weights = [int(input()) for _ in range(num_item)]
    left = 0
    right = 10000 * 100000
    while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
    print(right) def main():
    num_item, num_vehicle = list(map(int, input().split(" ")))
    weights = [int(input()) for _ in range(num_item)]
    left = 0
    right = 10000 * 100000
    while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
    print(right) main
def min_item_num(weights, num_item, num_vehicle, capacity):
    item_idx = 0
    for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
    return item_idx


def main():
    num_item, num_vehicle = list(map(int, input().split(" ")))
    weights = [int(input()) for _ in range(num_item)]
    left = 0
    right = 10000 * 100000
    while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
    print(right)


if __name__ == "__main__":
    main()

