def check(n, k, w, p):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= p:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i
    
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]

left, right = 0, 10 ** 10

while right - left > 1:
    mid = (left + right) // 2
    v = check(n, k, w, mid)
    if v >= n:
        right = mid
    else:
        left = mid

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

left, right = 0, 10 ** 10

while right - left > 1:
    mid = (left + right) // 2
    v = check(n, k, w, mid)
    if v >= n:
        right = mid
    else:
        left = mid

print(right)

