from collections import deque
n, k = input().rstrip().split(" ")
n = int(n)
k = int(k)
w_list = deque()
for _ in range(n):
    w_list.append(int(input().rstrip()))

def get_num_of_w(p, w_list, k):
    w_cnt = 0
    k_cnt = k
    temp_p = p
    temp_w_list = w_list.copy()

    while k_cnt > 0 and len(temp_w_list) > 0:
        w = temp_w_list[0]
        temp_p -= w
        if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
    return w_cnt  

    
left = 0
right = 10000 * 100000
min_p = 10000 * 100000
while left < right:
    mid = (left+right) // 2
    if get_num_of_w(mid, w_list, k) >= n:
        right = mid
        min_p = mid
    else:
        left = mid + 1
    
print(min_p)
    
    
    
    

        
    
    

        
     from collections import deque n, k = input().rstrip().split(" ") n input().rstrip().split(" ") ().rstrip().split ().rstrip() ().rstrip () input rstrip split " " k n = int(n) n int(n) int n k = int(k) k int(k) int k w_list = deque() w_list deque() deque for _ in range(n):
    w_list.append(int(input().rstrip())) _ range(n) range n w_list.append(int(input().rstrip())) w_list.append w_list append int(input().rstrip()) int input().rstrip() ().rstrip () input rstrip def get_num_of_w(p, w_list, k):
    w_cnt = 0
    k_cnt = k
    temp_p = p
    temp_w_list = w_list.copy()

    while k_cnt > 0 and len(temp_w_list) > 0:
        w = temp_w_list[0]
        temp_p -= w
        if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
    return w_cnt  

     get_num_of_w w_cnt = 0 w_cnt 0 k_cnt = k k_cnt k temp_p = p temp_p p temp_w_list = w_list.copy() temp_w_list w_list.copy() w_list.copy w_list copy while k_cnt > 0 and len(temp_w_list) > 0:
        w = temp_w_list[0]
        temp_p -= w
        if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
     k_cnt > 0 and len(temp_w_list) > 0 k_cnt > 0 k_cnt 0 len(temp_w_list) > 0 len(temp_w_list) len temp_w_list 0 w = temp_w_list[0] w temp_w_list[0] temp_w_list 0 temp_p -= w temp_p w if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
     temp_p >= 0 temp_p 0 temp_w_list.popleft() temp_w_list.popleft temp_w_list popleft w_cnt += 1 w_cnt 1 temp_p = p temp_p p k_cnt -= 1 k_cnt 1 return w_cnt w_cnt p p w_list w_list k k left = 0 left 0 right = 10000 * 100000 right 10000 * 100000 10000 100000 min_p = 10000 * 100000 min_p 10000 * 100000 10000 100000 while left < right:
    mid = (left+right) // 2
    if get_num_of_w(mid, w_list, k) >= n:
        right = mid
        min_p = mid
    else:
        left = mid + 1
     left < right left right mid = (left+right) // 2 mid (left+right) // 2 left+right left right 2 if get_num_of_w(mid, w_list, k) >= n:
        right = mid
        min_p = mid
    else:
        left = mid + 1
     get_num_of_w(mid, w_list, k) >= n get_num_of_w(mid, w_list, k) get_num_of_w mid w_list k n right = mid right mid min_p = mid min_p mid left = mid + 1 left mid + 1 mid 1 print(min_p) print min_p def get_num_of_w(p, w_list, k):
    w_cnt = 0
    k_cnt = k
    temp_p = p
    temp_w_list = w_list.copy()

    while k_cnt > 0 and len(temp_w_list) > 0:
        w = temp_w_list[0]
        temp_p -= w
        if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
    return w_cnt  

     def get_num_of_w(p, w_list, k):
    w_cnt = 0
    k_cnt = k
    temp_p = p
    temp_w_list = w_list.copy()

    while k_cnt > 0 and len(temp_w_list) > 0:
        w = temp_w_list[0]
        temp_p -= w
        if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
    return w_cnt  

     get_num_of_w k = int(k) int(k) k mid = (left+right) // 2 (left+right) // 2 mid right = 10000 * 100000 10000 * 100000 right w_list = deque() deque() w_list min_p = 10000 * 100000 10000 * 100000 min_p n = int(n) int(n) n min_p = mid mid min_p left = mid + 1 mid + 1 left n, k = input().rstrip().split(" ") input().rstrip().split(" ") n left = 0 0 left k = input().rstrip().split(" ") input().rstrip().split(" ") k right = mid mid right
from collections import deque
n, k = input().rstrip().split(" ")
n = int(n)
k = int(k)
w_list = deque()
for _ in range(n):
    w_list.append(int(input().rstrip()))

def get_num_of_w(p, w_list, k):
    w_cnt = 0
    k_cnt = k
    temp_p = p
    temp_w_list = w_list.copy()

    while k_cnt > 0 and len(temp_w_list) > 0:
        w = temp_w_list[0]
        temp_p -= w
        if temp_p >= 0:
            temp_w_list.popleft()
            w_cnt += 1
        else:
            temp_p = p
            k_cnt -= 1
    return w_cnt  

    
left = 0
right = 10000 * 100000
min_p = 10000 * 100000
while left < right:
    mid = (left+right) // 2
    if get_num_of_w(mid, w_list, k) >= n:
        right = mid
        min_p = mid
    else:
        left = mid + 1
    
print(min_p)
    
    
    
    

        
    
    

        
    
