def allocation():
    n, cars = map(int, input().split())
    weight = [int(input()) for i in range(n)]

    left = max(weight)
    right = sum(weight)

    while left < right:
        mid = (left + right) // 2

        if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

    print(left)

def check(weight, cars, capacity):
    t = 0
    c = 1
    for w in weight:
        t += w
        if t > capacity:
            t = w
            c += 1

    if c <= cars:
        return True
    else:
        return False

if __name__ == '__main__':
    allocation() def allocation():
    n, cars = map(int, input().split())
    weight = [int(input()) for i in range(n)]

    left = max(weight)
    right = sum(weight)

    while left < right:
        mid = (left + right) // 2

        if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

    print(left) allocation n, cars = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split cars int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input weight = [int(input()) for i in range(n)] weight [int(input()) for i in range(n)] left = max(weight) left max(weight) max weight right = sum(weight) right sum(weight) sum weight while left < right:
        mid = (left + right) // 2

        if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

     left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

     check(weight, cars, mid) check weight cars mid right = mid right mid left = mid + 1 left mid + 1 mid 1 print(left) print left def check(weight, cars, capacity):
    t = 0
    c = 1
    for w in weight:
        t += w
        if t > capacity:
            t = w
            c += 1

    if c <= cars:
        return True
    else:
        return False check t = 0 t 0 c = 1 c 1 for w in weight:
        t += w
        if t > capacity:
            t = w
            c += 1

     w weight t += w t w if t > capacity:
            t = w
            c += 1

     t > capacity t capacity t = w t w c += 1 c 1 if c <= cars:
        return True
    else:
        return False c <= cars c cars return True True return False False weight weight cars cars capacity capacity if __name__ == '__main__':
    allocation() __name__ == '__main__' __name__ '__main__' allocation() allocation def allocation():
    n, cars = map(int, input().split())
    weight = [int(input()) for i in range(n)]

    left = max(weight)
    right = sum(weight)

    while left < right:
        mid = (left + right) // 2

        if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

    print(left) def allocation():
    n, cars = map(int, input().split())
    weight = [int(input()) for i in range(n)]

    left = max(weight)
    right = sum(weight)

    while left < right:
        mid = (left + right) // 2

        if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

    print(left) allocation def check(weight, cars, capacity):
    t = 0
    c = 1
    for w in weight:
        t += w
        if t > capacity:
            t = w
            c += 1

    if c <= cars:
        return True
    else:
        return False def check(weight, cars, capacity):
    t = 0
    c = 1
    for w in weight:
        t += w
        if t > capacity:
            t = w
            c += 1

    if c <= cars:
        return True
    else:
        return False check
def allocation():
    n, cars = map(int, input().split())
    weight = [int(input()) for i in range(n)]

    left = max(weight)
    right = sum(weight)

    while left < right:
        mid = (left + right) // 2

        if check(weight, cars, mid):
            right = mid
        else:
            left = mid + 1

    print(left)

def check(weight, cars, capacity):
    t = 0
    c = 1
    for w in weight:
        t += w
        if t > capacity:
            t = w
            c += 1

    if c <= cars:
        return True
    else:
        return False

if __name__ == '__main__':
    allocation()