def check(n, k, W, P):
    i = 0
    for _ in range(k):
        capacity = 0
        while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
    return i

def solve(n, k, W):
    left = 0
    right = (10 ** 5) * (10 ** 5)
    mid = 0
    while (right - left) > 1:
        mid = (right + left) // 2
        v = check(n, k, W, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
print(solve(n, k, W))
 def check(n, k, W, P):
    i = 0
    for _ in range(k):
        capacity = 0
        while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
    return i check i = 0 i 0 for _ in range(k):
        capacity = 0
        while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
     _ range(k) range k capacity = 0 capacity 0 while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
     capacity + W[i] <= P capacity + W[i] capacity W[i] W i P capacity += W[i] capacity W[i] W i i += 1 i 1 if i == n:
                return n
     i == n i n return n n return i i n n k k W W P P def solve(n, k, W):
    left = 0
    right = (10 ** 5) * (10 ** 5)
    mid = 0
    while (right - left) > 1:
        mid = (right + left) // 2
        v = check(n, k, W, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right solve left = 0 left 0 right = (10 ** 5) * (10 ** 5) right (10 ** 5) * (10 ** 5) 10 ** 5 10 5 10 ** 5 10 5 mid = 0 mid 0 while (right - left) > 1:
        mid = (right + left) // 2
        v = check(n, k, W, mid)
        if v >= n:
            right = mid
        else:
            left = mid
     (right - left) > 1 right - left right left 1 mid = (right + left) // 2 mid (right + left) // 2 right + left right left 2 v = check(n, k, W, mid) v check(n, k, W, mid) check n k W mid if v >= n:
            right = mid
        else:
            left = mid
     v >= n v n right = mid right mid left = mid left mid return right right n n k k W 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)] print(solve(n, k, W)) print solve(n, k, W) solve n k W def solve(n, k, W):
    left = 0
    right = (10 ** 5) * (10 ** 5)
    mid = 0
    while (right - left) > 1:
        mid = (right + left) // 2
        v = check(n, k, W, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right def solve(n, k, W):
    left = 0
    right = (10 ** 5) * (10 ** 5)
    mid = 0
    while (right - left) > 1:
        mid = (right + left) // 2
        v = check(n, k, W, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right solve n, k = map(int, input().split()) map(int, input().split()) n W = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W def check(n, k, W, P):
    i = 0
    for _ in range(k):
        capacity = 0
        while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
    return i def check(n, k, W, P):
    i = 0
    for _ in range(k):
        capacity = 0
        while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
    return i check k = map(int, input().split()) map(int, input().split()) k
def check(n, k, W, P):
    i = 0
    for _ in range(k):
        capacity = 0
        while capacity + W[i] <= P:
            capacity += W[i]
            i += 1
            if i == n:
                return n
    return i

def solve(n, k, W):
    left = 0
    right = (10 ** 5) * (10 ** 5)
    mid = 0
    while (right - left) > 1:
        mid = (right + left) // 2
        v = check(n, k, W, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

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

