def track_number_needed(p, n_track):
    global W
    n_luggage = 0
    for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
    return n_luggage


def binary_search():
    global n
    global k
    left = 0
    right = 100000 * 10000
    while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
    return right
            


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

 def track_number_needed(p, n_track):
    global W
    n_luggage = 0
    for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
    return n_luggage track_number_needed global W n_luggage = 0 n_luggage 0 for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
     j range(n_track) range n_track weight_sum = 0 weight_sum 0 while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
     weight_sum + W[n_luggage] <= p weight_sum + W[n_luggage] weight_sum W[n_luggage] W n_luggage p weight_sum += W[n_luggage] weight_sum W[n_luggage] W n_luggage n_luggage += 1 n_luggage 1 if n_luggage == len(W):
                return n
     n_luggage == len(W) n_luggage len(W) len W return n n return n_luggage n_luggage p p n_track n_track def binary_search():
    global n
    global k
    left = 0
    right = 100000 * 10000
    while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
    return right
             binary_search global n global k left = 0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
     right - left > 1 right - left right left 1 mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 n_luggage = track_number_needed(mid, k) n_luggage track_number_needed(mid, k) track_number_needed mid k if n_luggage >= n:
            right = mid
        else:
            left = mid
     n_luggage >= n n_luggage n right = mid right mid left = mid left mid return right right if __name__ == "__main__":
    n, k = map(int, input().split())
    W = [int(input()) for i in range(n)]
    print(binary_search()) __name__ == "__main__" __name__ "__main__" n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k 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 W = [int(input()) for i in range(n)] W [int(input()) for i in range(n)] print(binary_search()) print binary_search() binary_search W = [int(input()) for i in range(n)] [int(input()) for i in range(n)] W n, k = map(int, input().split()) map(int, input().split()) n def track_number_needed(p, n_track):
    global W
    n_luggage = 0
    for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
    return n_luggage def track_number_needed(p, n_track):
    global W
    n_luggage = 0
    for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
    return n_luggage track_number_needed k = map(int, input().split()) map(int, input().split()) k def binary_search():
    global n
    global k
    left = 0
    right = 100000 * 10000
    while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
    return right
             def binary_search():
    global n
    global k
    left = 0
    right = 100000 * 10000
    while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
    return right
             binary_search
def track_number_needed(p, n_track):
    global W
    n_luggage = 0
    for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
    return n_luggage


def binary_search():
    global n
    global k
    left = 0
    right = 100000 * 10000
    while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
    return right
            


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


