import sys
input = sys.stdin.readline

def judge(x):
    now, cnt = 0, 0
    
    for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
    if now>0:
        cnt += 1
    
    return cnt<=k

def binary_search():
    l, r = max(w), 10**10
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
print(binary_search())
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def judge(x):
    now, cnt = 0, 0
    
    for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
    if now>0:
        cnt += 1
    
    return cnt<=k judge now, cnt = 0, 0 now 0 cnt 0 for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
     i range(n) range n if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
     now+w[i]<=x now+w[i] now w[i] w i x now += w[i] now w[i] w i cnt += 1 cnt 1 now = w[i] now w[i] w i if now>0:
        cnt += 1
    
     now>0 now 0 cnt += 1 cnt 1 return cnt<=k cnt<=k cnt k x x def binary_search():
    l, r = max(w), 10**10
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l binary_search l, r = max(w), 10**10 l max(w) max w r 10**10 10 10 while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
     l<=r l r m = (l+r)//2 m (l+r)//2 l+r l r 2 if judge(m):
            r = m-1
        else:
            l = m+1
    
     judge(m) judge m r = m-1 r m-1 m 1 l = m+1 l m+1 m 1 return l l 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)] print(binary_search()) print binary_search() binary_search def judge(x):
    now, cnt = 0, 0
    
    for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
    if now>0:
        cnt += 1
    
    return cnt<=k def judge(x):
    now, cnt = 0, 0
    
    for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
    if now>0:
        cnt += 1
    
    return cnt<=k judge w = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] w input = sys.stdin.readline sys.stdin.readline input k = map(int, input().split()) map(int, input().split()) k def binary_search():
    l, r = max(w), 10**10
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l def binary_search():
    l, r = max(w), 10**10
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l binary_search n, k = map(int, input().split()) map(int, input().split()) n
import sys
input = sys.stdin.readline

def judge(x):
    now, cnt = 0, 0
    
    for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
    if now>0:
        cnt += 1
    
    return cnt<=k

def binary_search():
    l, r = max(w), 10**10
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

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

