def check(p):
    j = 0 # 積んだ荷物の個数
    for i in range(k):
        track = 0
        while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
    return j

def solve():
    right = 100000 * 10000
    left = 0
    mid = (right + left) // 2
    while right - left > 0:
        cnt = check(mid)
        if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

    return mid

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

print(solve())
 def check(p):
    j = 0 # 積んだ荷物の個数
    for i in range(k):
        track = 0
        while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
    return j check j = 0 j 0 for i in range(k):
        track = 0
        while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
     i range(k) range k track = 0 track 0 while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
     track + w[j] <= p track + w[j] track w[j] w j p track += w[j] track w[j] w j j += 1 j 1 if j == n:
                return n
     j == n j n return n n return j j p p def solve():
    right = 100000 * 10000
    left = 0
    mid = (right + left) // 2
    while right - left > 0:
        cnt = check(mid)
        if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

    return mid solve right = 100000 * 10000 right 100000 * 10000 100000 10000 left = 0 left 0 mid = (right + left) // 2 mid (right + left) // 2 right + left right left 2 while right - left > 0:
        cnt = check(mid)
        if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

     right - left > 0 right - left right left 0 cnt = check(mid) cnt check(mid) check mid if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

     cnt == n cnt n right = mid right mid mid = (right + left) // 2 mid (right + left) // 2 right + left right left 2 left = mid + 1 left mid + 1 mid 1 mid = (right + left) // 2 mid (right + left) // 2 right + left right left 2 return mid mid n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w = [] w [] for _ in range(n):
    w.append(int(input())) _ range(n) range n w.append(int(input())) w.append w append int(input()) int input() input print(solve()) print solve() solve w = [] [] w k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n def check(p):
    j = 0 # 積んだ荷物の個数
    for i in range(k):
        track = 0
        while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
    return j def check(p):
    j = 0 # 積んだ荷物の個数
    for i in range(k):
        track = 0
        while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
    return j check def solve():
    right = 100000 * 10000
    left = 0
    mid = (right + left) // 2
    while right - left > 0:
        cnt = check(mid)
        if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

    return mid def solve():
    right = 100000 * 10000
    left = 0
    mid = (right + left) // 2
    while right - left > 0:
        cnt = check(mid)
        if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

    return mid solve
def check(p):
    j = 0 # 積んだ荷物の個数
    for i in range(k):
        track = 0
        while track + w[j] <= p:
            track += w[j]
            j += 1
            if j == n:
                return n
    return j

def solve():
    right = 100000 * 10000
    left = 0
    mid = (right + left) // 2
    while right - left > 0:
        cnt = check(mid)
        if cnt == n:
            right = mid
            mid = (right + left) // 2
        else:
            left = mid + 1
            mid = (right + left) // 2

    return mid

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

print(solve())

