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


def binarysearch(start, end):
    left = start
    right = end
    mid = 0

    while left < right:
        mid = (left + right)//2
        # print(mid)
        if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
    return mid


def simulate(prb, wei, dai):
    cnt = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
    return True

print(binarysearch(max(w), sum(w))) 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 binarysearch(start, end):
    left = start
    right = end
    mid = 0

    while left < right:
        mid = (left + right)//2
        # print(mid)
        if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
    return mid binarysearch left = start left start right = end right end mid = 0 mid 0 while left < right:
        mid = (left + right)//2
        # print(mid)
        if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
     left < right left right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
     simulate(mid, w, k) simulate mid w k right = mid right mid mid += 1 mid 1 left = mid left mid return mid mid start start end end def simulate(prb, wei, dai):
    cnt = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
    return True simulate cnt = 1 cnt 1 tmp = 0 tmp 0 for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
     j wei tmp += j tmp j if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
     tmp > prb tmp prb tmp = j tmp j cnt += 1 cnt 1 if cnt > dai:
                return False
     cnt > dai cnt dai return False False return True True prb prb wei wei dai dai print(binarysearch(max(w), sum(w))) print binarysearch(max(w), sum(w)) binarysearch max(w) max w sum(w) sum w w = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] w def binarysearch(start, end):
    left = start
    right = end
    mid = 0

    while left < right:
        mid = (left + right)//2
        # print(mid)
        if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
    return mid def binarysearch(start, end):
    left = start
    right = end
    mid = 0

    while left < right:
        mid = (left + right)//2
        # print(mid)
        if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
    return mid binarysearch n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k def simulate(prb, wei, dai):
    cnt = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
    return True def simulate(prb, wei, dai):
    cnt = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
    return True simulate
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]


def binarysearch(start, end):
    left = start
    right = end
    mid = 0

    while left < right:
        mid = (left + right)//2
        # print(mid)
        if simulate(mid, w, k):
            right = mid
            # print("ok")
        else:
            mid += 1
            left = mid
    return mid


def simulate(prb, wei, dai):
    cnt = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            cnt += 1
            if cnt > dai:
                return False
    return True

print(binarysearch(max(w), sum(w)))