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(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) 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 calc_allocatable_packet """ ?????????????????°?????????????????§?????????????±?????????????n??°??????????????????????????????????????°????±??????? """ num_of_packets = len(packets) num_of_packets len(packets) len packets next_p = 0 next_p 0 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  # ?¬???????????????????
     t range(num_of_trucks) range num_of_trucks payload = 0 payload 0 while next_p < num_of_packets:
            if payload + packets[next_p] <= p_max:  # ?¬?????????????????????§???????
                payload += packets[next_p]
                next_p += 1
            else:
                break  # ?¬???????????????????
     next_p < num_of_packets next_p num_of_packets if payload + packets[next_p] <= p_max:  # ?¬?????????????????????§???????
                payload += packets[next_p]
                next_p += 1
            else:
                break  # ?¬???????????????????
     payload + packets[next_p] <= p_max payload + packets[next_p] payload packets[next_p] packets next_p p_max payload += packets[next_p] payload packets[next_p] packets next_p next_p += 1 next_p 1 break return next_p next_p packets packets num_of_trucks num_of_trucks p_max p_max 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 calc_minimum_payload num_of_packets = len(packets) num_of_packets len(packets) len packets lower_limit = packets[0] lower_limit packets[0] packets 0 upper_limit = 10000 * num_of_packets upper_limit 10000 * num_of_packets 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

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

     result < num_of_packets result num_of_packets lower_limit = middle + 1 lower_limit middle + 1 middle 1 upper_limit = middle upper_limit middle return lower_limit lower_limit packets packets num_of_trucks num_of_trucks if __name__ == '__main__':
    # ??????????????\???
    num_of_packets, num_of_trucks = [int(x) for x in input().split(' ')]
    packets = [int(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) __name__ == '__main__' __name__ '__main__' int(x) for x in input().split(' ') for x in input().split(' ') x input().split(' ') ().split () input split ' ' for x in input().split(' ') int(x) int x num_of_packets, num_of_trucks = [int(x) for x in input().split(' ')] num_of_packets [int(x) for x in input().split(' ')] num_of_trucks int(input()) for _ in range(num_of_packets) for _ in range(num_of_packets) _ range(num_of_packets) range num_of_packets for _ in range(num_of_packets) int(input()) int input() input packets = [int(input()) for _ in range(num_of_packets)] packets [int(input()) for _ in range(num_of_packets)] result = calc_minimum_payload(packets, num_of_trucks) result calc_minimum_payload(packets, num_of_trucks) calc_minimum_payload packets num_of_trucks print(result) print result num_of_trucks = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] num_of_trucks result = calc_minimum_payload(packets, num_of_trucks) calc_minimum_payload(packets, num_of_trucks) result 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_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 calc_allocatable_packet num_of_packets, num_of_trucks = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] num_of_packets packets = [int(input()) for _ in range(num_of_packets)] [int(input()) for _ in range(num_of_packets)] packets 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 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 calc_minimum_payload
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(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)