# Allocation
from collections import deque

n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]


def can_load(P):
    num_track = 1
    load = 0
    for w in W:
        if w > P:
            return False

        if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

    return True


def binary_search():
    top = 0
    bottom = sum(W)+1

    while top < bottom:
        mid = (top+bottom)//2

        if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

    return top


print(binary_search())
 from collections import deque n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input W = [int(input()) for _ in range(n)] W [int(input()) for _ in range(n)] def can_load(P):
    num_track = 1
    load = 0
    for w in W:
        if w > P:
            return False

        if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

    return True can_load num_track = 1 num_track 1 load = 0 load 0 for w in W:
        if w > P:
            return False

        if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

     w W if w > P:
            return False

         w > P w P return False False if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

     load + w > P load + w load w P if num_track == k:
                return False

             num_track == k num_track k return False False num_track += 1 num_track 1 load = w load w load += w load w return True True P P def binary_search():
    top = 0
    bottom = sum(W)+1

    while top < bottom:
        mid = (top+bottom)//2

        if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

    return top binary_search top = 0 top 0 bottom = sum(W)+1 bottom sum(W)+1 sum(W) sum W 1 while top < bottom:
        mid = (top+bottom)//2

        if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

     top < bottom top bottom mid = (top+bottom)//2 mid (top+bottom)//2 top+bottom top bottom 2 if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

     can_load(P=mid) can_load P=mid P mid bottom = mid bottom mid top = mid + 1 top mid + 1 mid 1 return top top print(binary_search()) print binary_search() binary_search k = map(int, input().split()) map(int, input().split()) k W = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W def can_load(P):
    num_track = 1
    load = 0
    for w in W:
        if w > P:
            return False

        if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

    return True def can_load(P):
    num_track = 1
    load = 0
    for w in W:
        if w > P:
            return False

        if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

    return True can_load def binary_search():
    top = 0
    bottom = sum(W)+1

    while top < bottom:
        mid = (top+bottom)//2

        if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

    return top def binary_search():
    top = 0
    bottom = sum(W)+1

    while top < bottom:
        mid = (top+bottom)//2

        if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

    return top binary_search n, k = map(int, input().split()) map(int, input().split()) n
# Allocation
from collections import deque

n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]


def can_load(P):
    num_track = 1
    load = 0
    for w in W:
        if w > P:
            return False

        if load + w > P:
            if num_track == k:
                return False

            num_track += 1
            load = w

        else:
            load += w

    return True


def binary_search():
    top = 0
    bottom = sum(W)+1

    while top < bottom:
        mid = (top+bottom)//2

        if can_load(P=mid):
            bottom = mid
        else:
            top = mid + 1

    return top


print(binary_search())

