def check(p):
    s = w[0]
    track = 1
    for i in range(1, n):
        if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
    return True

n, k = [int(i) for i in input().split()]
w = []
for i in range(n):
    w.append(int(input()))
L = max(w)
R = sum(w)

if check(L):
    print(L)
else:
    while L + 1 < R:
        M = (L + R) // 2
        if check(M):
            R = M
        else:
            L = M
    print(R) def check(p):
    s = w[0]
    track = 1
    for i in range(1, n):
        if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
    return True check s = w[0] s w[0] w 0 track = 1 track 1 for i in range(1, n):
        if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
     i range(1, n) range 1 n if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
     s + w[i] <= p s + w[i] s w[i] w i p s += w[i] s w[i] w i track += 1 track 1 if track > k: return False
             track > k track k s = w[i] s w[i] w i return True True p p int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, k = [int(i) for i in input().split()] n [int(i) for i in input().split()] k w = [] w [] for i in range(n):
    w.append(int(input())) i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input L = max(w) L max(w) max w R = sum(w) R sum(w) sum w if check(L):
    print(L)
else:
    while L + 1 < R:
        M = (L + R) // 2
        if check(M):
            R = M
        else:
            L = M
    print(R) check(L) check L print(L) print L while L + 1 < R:
        M = (L + R) // 2
        if check(M):
            R = M
        else:
            L = M
     L + 1 < R L + 1 L 1 R M = (L + R) // 2 M (L + R) // 2 L + R L R 2 if check(M):
            R = M
        else:
            L = M
     check(M) check M R = M R M L = M L M print(R) print R R = M M R k = [int(i) for i in input().split()] [int(i) for i in input().split()] k w = [] [] w L = M M L L = max(w) max(w) L n, k = [int(i) for i in input().split()] [int(i) for i in input().split()] n def check(p):
    s = w[0]
    track = 1
    for i in range(1, n):
        if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
    return True def check(p):
    s = w[0]
    track = 1
    for i in range(1, n):
        if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
    return True check R = sum(w) sum(w) R M = (L + R) // 2 (L + R) // 2 M
def check(p):
    s = w[0]
    track = 1
    for i in range(1, n):
        if s + w[i] <= p:
            s += w[i]
        else:
            track += 1
            if track > k: return False
            s = w[i]
    return True

n, k = [int(i) for i in input().split()]
w = []
for i in range(n):
    w.append(int(input()))
L = max(w)
R = sum(w)

if check(L):
    print(L)
else:
    while L + 1 < R:
        M = (L + R) // 2
        if check(M):
            R = M
        else:
            L = M
    print(R)