# coding: utf-8
# 二分探索（応用）


def loading(pack_list, k, q):

    truck = 0
    idx = 0
    for pack in pack_list:
        if pack > q:
            return False

        if truck + pack > q:
            idx += 1
            truck = 0

        truck += pack

    if truck > 0:
        idx += 1

    return False if idx > k else True


if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]

    pack = []

    for _ in range(n):
        pack.append(int(input()))

    min = 0
    max = int(1E20)
    # min = sum(pack) // n
    # max = sum(pack)

    q = (max + min) // 2

    res = loading(pack, k, q)

    while min + 1 != max:
        min, max = [min, q] if res else [q, max]
        q = (max + min) // 2

        res = loading(pack, k, q)

    print(max)
 def loading(pack_list, k, q):

    truck = 0
    idx = 0
    for pack in pack_list:
        if pack > q:
            return False

        if truck + pack > q:
            idx += 1
            truck = 0

        truck += pack

    if truck > 0:
        idx += 1

    return False if idx > k else True loading truck = 0 truck 0 idx = 0 idx 0 for pack in pack_list:
        if pack > q:
            return False

        if truck + pack > q:
            idx += 1
            truck = 0

        truck += pack

     pack pack_list if pack > q:
            return False

         pack > q pack q return False False if truck + pack > q:
            idx += 1
            truck = 0

         truck + pack > q truck + pack truck pack q idx += 1 idx 1 truck = 0 truck 0 truck += pack truck pack if truck > 0:
        idx += 1

     truck > 0 truck 0 idx += 1 idx 1 return False if idx > k else True False if idx > k else True idx > k idx k False True pack_list pack_list k k q q if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]

    pack = []

    for _ in range(n):
        pack.append(int(input()))

    min = 0
    max = int(1E20)
    # min = sum(pack) // n
    # max = sum(pack)

    q = (max + min) // 2

    res = loading(pack, k, q)

    while min + 1 != max:
        min, max = [min, q] if res else [q, max]
        q = (max + min) // 2

        res = loading(pack, k, q)

    print(max) __name__ == "__main__" __name__ "__main__" int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, k = [int(i) for i in input().split()] n [int(i) for i in input().split()] k pack = [] pack [] for _ in range(n):
        pack.append(int(input()))

     _ range(n) range n pack.append(int(input())) pack.append pack append int(input()) int input() input min = 0 min 0 max = int(1E20) max int(1E20) int 1E20 q = (max + min) // 2 q (max + min) // 2 max + min max min 2 res = loading(pack, k, q) res loading(pack, k, q) loading pack k q while min + 1 != max:
        min, max = [min, q] if res else [q, max]
        q = (max + min) // 2

        res = loading(pack, k, q)

     min + 1 != max min + 1 min 1 max min, max = [min, q] if res else [q, max] min [min, q] if res else [q, max] res [min, q] min q [q, max] q max max q = (max + min) // 2 q (max + min) // 2 max + min max min 2 res = loading(pack, k, q) res loading(pack, k, q) loading pack k q print(max) print max q = (max + min) // 2 (max + min) // 2 q res = loading(pack, k, q) loading(pack, k, q) res n, k = [int(i) for i in input().split()] [int(i) for i in input().split()] n def loading(pack_list, k, q):

    truck = 0
    idx = 0
    for pack in pack_list:
        if pack > q:
            return False

        if truck + pack > q:
            idx += 1
            truck = 0

        truck += pack

    if truck > 0:
        idx += 1

    return False if idx > k else True def loading(pack_list, k, q):

    truck = 0
    idx = 0
    for pack in pack_list:
        if pack > q:
            return False

        if truck + pack > q:
            idx += 1
            truck = 0

        truck += pack

    if truck > 0:
        idx += 1

    return False if idx > k else True loading min, max = [min, q] if res else [q, max] [min, q] if res else [q, max] min min = 0 0 min q = (max + min) // 2 (max + min) // 2 q k = [int(i) for i in input().split()] [int(i) for i in input().split()] k max = int(1E20) int(1E20) max res = loading(pack, k, q) loading(pack, k, q) res pack = [] [] pack max = [min, q] if res else [q, max] [min, q] if res else [q, max] max
# coding: utf-8
# 二分探索（応用）


def loading(pack_list, k, q):

    truck = 0
    idx = 0
    for pack in pack_list:
        if pack > q:
            return False

        if truck + pack > q:
            idx += 1
            truck = 0

        truck += pack

    if truck > 0:
        idx += 1

    return False if idx > k else True


if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]

    pack = []

    for _ in range(n):
        pack.append(int(input()))

    min = 0
    max = int(1E20)
    # min = sum(pack) // n
    # max = sum(pack)

    q = (max + min) // 2

    res = loading(pack, k, q)

    while min + 1 != max:
        min, max = [min, q] if res else [q, max]
        q = (max + min) // 2

        res = loading(pack, k, q)

    print(max)

