def check(P,w,n):
    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

s = input().split(" ")
n = int(s[0])
k = int(s[1])
w = []
for i in range(n):
    a = int(input())
    w.append(a)

left = 0
right = 100000 * 10000
while right - left > 1:
    mid = int((right + left) / 2)
    v = check(mid,w,n)
    if v >= n:
        right = mid
    else:
        left = mid
print(right) def check(P,w,n):
    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 P P w w n n s = input().split(" ") s input().split(" ") ().split () input split " " n = int(s[0]) n int(s[0]) int s[0] s 0 k = int(s[1]) k int(s[1]) int s[1] s 1 w = [] w [] for i in range(n):
    a = int(input())
    w.append(a) i range(n) range n a = int(input()) a int(input()) int input() input w.append(a) w.append w append a left = 0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 while right - left > 1:
    mid = int((right + left) / 2)
    v = check(mid,w,n)
    if v >= n:
        right = mid
    else:
        left = mid right - left > 1 right - left right left 1 mid = int((right + left) / 2) mid int((right + left) / 2) int (right + left) / 2 right + left right left 2 v = check(mid,w,n) v check(mid,w,n) check mid w n if v >= n:
        right = mid
    else:
        left = mid v >= n v n right = mid right mid left = mid left mid print(right) print right n = int(s[0]) int(s[0]) n a = int(input()) int(input()) a right = 100000 * 10000 100000 * 10000 right w = [] [] w left = mid mid left k = int(s[1]) int(s[1]) k mid = int((right + left) / 2) int((right + left) / 2) mid left = 0 0 left def check(P,w,n):
    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(P,w,n):
    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 s = input().split(" ") input().split(" ") s v = check(mid,w,n) check(mid,w,n) v right = mid mid right
def check(P,w,n):
    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

s = input().split(" ")
n = int(s[0])
k = int(s[1])
w = []
for i in range(n):
    a = int(input())
    w.append(a)

left = 0
right = 100000 * 10000
while right - left > 1:
    mid = int((right + left) / 2)
    v = check(mid,w,n)
    if v >= n:
        right = mid
    else:
        left = mid
print(right)