# Original solution
def calc_allocatable_packet(packets, num_of_trucks, p_max):
    """ ?????????????????°?????????????????§?????????????±?????????????n??°??????????????????????????????????????°????±??????? """
    num_of_packets = len(packets)
    next_p = 0  # ?????°?????????????????° ??? ?¬????packet[i]?????????????????????
    for t in range(num_of_trucks):
        payload = 0  # ??????????????????????????????
        while next_p < num_of_packets:
            if payload + packets[next_p] <= p_max:  # ?¬?????????????????????§???????
                payload += packets[next_p]
                next_p += 1
            else:
                break  # ?¬???????????????????
    return next_p


def get_ball_park_estimate(packets, num_of_trucks):
    num_of_packets = len(packets)
    upper_limit = 10000 * num_of_packets
    result = calc_allocatable_packet(packets, num_of_trucks, upper_limit)
    while result >= num_of_packets:
        upper_limit //= 2
        result = calc_allocatable_packet(packets, num_of_trucks, upper_limit)
    return upper_limit // 2, upper_limit


def calc_minimum_payload(packets, num_of_trucks):
    lower_limit, upper_limit = get_ball_park_estimate(packets, num_of_trucks)
    num_of_packets = len(packets)
    p_max = lower_limit
    result = calc_allocatable_packet(packets, num_of_trucks, p_max)
    while result < num_of_packets:
        p_max += 1
        result = calc_allocatable_packet(packets, num_of_trucks, p_max)
    return p_max

    #num_of_packets = len(packets)
    #p_max = packets[0]
    #result = calc_allocatable_packet(packets, num_of_trucks, p_max)
    #while result < num_of_packets:
    #    p_max += 1
    #    result = calc_allocatable_packet(packets, num_of_trucks, p_max)
    #return p_max



if __name__ == '__main__':
    # ??????????????\???
    num_of_packets, num_of_trucks = [int(x) for x in input().split(' ')]
    packets = [int(eval(input())) for _ in range(num_of_packets)]
    # packets = [8, 1, 7, 3, 9]

    # ???????????????
    result = calc_minimum_payload(packets, num_of_trucks)

    # ???????????¨???
    print(result)

# Optimized solution
def calc_allocatable_packet(packets, num_of_trucks, p_max):
    """ ?????????????????°?????????????????§?????????????±?????????????n??°??????????????????????????????????????°????±??????? """
    num_of_packets = len(packets)
    next_p = 0  # ?????°?????????????????° ??? ?¬????packet[i]?????????????????????
    for t in range(num_of_trucks):
        payload = 0  # ??????????????????????????????
        while next_p < num_of_packets:
            if payload + packets[next_p] <= p_max:  # ?¬?????????????????????§???????
                payload += packets[next_p]
                next_p += 1
            else:
                break  # ?¬???????????????????
    return next_p


def calc_minimum_payload(packets, num_of_trucks):
    num_of_packets = len(packets)
    lower_limit = packets[0]
    upper_limit = 10000 * num_of_packets

    while lower_limit < upper_limit:
        middle = (lower_limit + upper_limit) // 2
        result = calc_allocatable_packet(packets, num_of_trucks, middle)
        if result < num_of_packets:
            lower_limit = middle + 1
        else:
            upper_limit = middle

    return lower_limit


if __name__ == '__main__':
    # ??????????????\???
    num_of_packets, num_of_trucks = [int(x) for x in input().split(' ')]
    packets = [int(eval(input())) for _ in range(num_of_packets)]
    # num_of_packets, num_of_trucks = 0, 0
    # packets = []
    # with open('ALDS1_4_D_in25.txt') as f:
    #    for line in f:
    #       if ' ' not in line:
    #           packets.append(int(line))
    #       else:
    #           num_of_packets, num_of_trucks = [int(x) for x in line.split(' ')]



    # ???????????????
    result = calc_minimum_payload(packets, num_of_trucks)

    # ???????????¨???
    print(result)