import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15


N,K = map(int,input().split())
W = [int(input()) for _ in range(N)]

r = 10 ** 10
l = 0
def ok(x):
    cnt = 1
    tot = 0
    for i in range(N):
        if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
    return cnt <= K      

while r - l > 1:
    mid = (r + l)//2
    if ok(mid):
        r = mid
    else:
        l = mid
print(r)
 import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = 10 ** 15 INF 10 ** 15 10 15 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)] r = 10 ** 10 r 10 ** 10 10 10 l = 0 l 0 def ok(x):
    cnt = 1
    tot = 0
    for i in range(N):
        if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
    return cnt <= K       ok cnt = 1 cnt 1 tot = 0 tot 0 for i in range(N):
        if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
     i range(N) range N if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
     tot + W[i] <= x tot + W[i] tot W[i] W i x tot += W[i] tot W[i] W i cnt += 1 cnt 1 if W[i] > x:
                return False
             W[i] > x W[i] W i x return False False tot = W[i] tot W[i] W i return cnt <= K cnt <= K cnt K x x while r - l > 1:
    mid = (r + l)//2
    if ok(mid):
        r = mid
    else:
        l = mid r - l > 1 r - l r l 1 mid = (r + l)//2 mid (r + l)//2 r + l r l 2 if ok(mid):
        r = mid
    else:
        l = mid ok(mid) ok mid r = mid r mid l = mid l mid print(r) print r W = [int(input()) for _ in range(N)] [int(input()) for _ in range(N)] W MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD l = 0 0 l r = mid mid r mid = (r + l)//2 (r + l)//2 mid l = mid mid l r = 10 ** 10 10 ** 10 r N,K = map(int,input().split()) map(int,input().split()) N def ok(x):
    cnt = 1
    tot = 0
    for i in range(N):
        if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
    return cnt <= K       def ok(x):
    cnt = 1
    tot = 0
    for i in range(N):
        if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
    return cnt <= K       ok INF = 10 ** 15 10 ** 15 INF K = map(int,input().split()) map(int,input().split()) K
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15


N,K = map(int,input().split())
W = [int(input()) for _ in range(N)]

r = 10 ** 10
l = 0
def ok(x):
    cnt = 1
    tot = 0
    for i in range(N):
        if tot + W[i] <= x:
            tot += W[i]
        else:
            cnt += 1
            if W[i] > x:
                return False
            tot = W[i]
    return cnt <= K      

while r - l > 1:
    mid = (r + l)//2
    if ok(mid):
        r = mid
    else:
        l = mid
print(r)

