import sys

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 = map(int, sys.stdin.readline().strip().split())
w = []
for i in range(n):
    w.append(int(sys.stdin.readline()))

L = max(w)
if check(L):
    print(L)
else:
    R = sum(w)
    assert check(R)

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

    print(R) import sys sys 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 n, k = map(int, sys.stdin.readline().strip().split()) n map(int, sys.stdin.readline().strip().split()) map int sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split k w = [] w [] for i in range(n):
    w.append(int(sys.stdin.readline())) i range(n) range n w.append(int(sys.stdin.readline())) w.append w append int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline L = max(w) L max(w) max w if check(L):
    print(L)
else:
    R = sum(w)
    assert check(R)

    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 R = sum(w) R sum(w) sum w assert check(R) check(R) check R 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 k = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) k M = (L + R) // 2 (L + R) // 2 M n, k = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().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 w = [] [] w R = M M R L = max(w) max(w) L R = sum(w) sum(w) R L = M M L
import sys

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 = map(int, sys.stdin.readline().strip().split())
w = []
for i in range(n):
    w.append(int(sys.stdin.readline()))

L = max(w)
if check(L):
    print(L)
else:
    R = sum(w)
    assert check(R)

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

    print(R)