#define k from p
def calck(all_w, p):
    count = 0
    sum = 0
    for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
    return count+1

#get n and k
n, k =map(lambda x: int(x), input().split(' '))

#get all w
#set min and max of p
all_w = []
max = -1
sum = 0
for i in range(n):
    w = int(input())
    all_w.append(w)
    if w > max:
        max = w
    sum += w
max_weight = max
sum_weight = sum
min, max = max, sum
#binary search of p

while min<=max:
    p_pointer = (min+max)//2
    calcedk = calck(all_w, p_pointer)
    if calcedk > k:
        min = p_pointer+1
    elif p_pointer == max_weight or calck(all_w, p_pointer-1) > k:
        print(p_pointer)
        break
    else:
        max = p_pointer-1 def calck(all_w, p):
    count = 0
    sum = 0
    for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
    return count+1

#get n and k calck count = 0 count 0 sum = 0 sum 0 for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
     w all_w if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
     sum + w <= p sum + w sum w p sum += w sum w count+=1 count 1 sum = w sum w return count+1 count+1 count 1 all_w all_w p p n, k =map(lambda x: int(x), input().split(' ')) n map(lambda x: int(x), input().split(' ')) map lambda x: int(x) int(x) int x x input().split(' ') ().split () input split ' ' k all_w = [] all_w [] max = -1 max -1 sum = 0 sum 0 for i in range(n):
    w = int(input())
    all_w.append(w)
    if w > max:
        max = w
    sum += w i range(n) range n w = int(input()) w int(input()) int input() input all_w.append(w) all_w.append all_w append w if w > max:
        max = w
     w > max w max max = w max w sum += w sum w max_weight = max max_weight max sum_weight = sum sum_weight sum min, max = max, sum min max max sum while min<=max:
    p_pointer = (min+max)//2
    calcedk = calck(all_w, p_pointer)
    if calcedk > k:
        min = p_pointer+1
    elif p_pointer == max_weight or calck(all_w, p_pointer-1) > k:
        print(p_pointer)
        break
    else:
        max = p_pointer-1 min<=max min max p_pointer = (min+max)//2 p_pointer (min+max)//2 min+max min max 2 calcedk = calck(all_w, p_pointer) calcedk calck(all_w, p_pointer) calck all_w p_pointer if calcedk > k:
        min = p_pointer+1
    elif p_pointer == max_weight or calck(all_w, p_pointer-1) > k:
        print(p_pointer)
        break
    else:
        max = p_pointer-1 calcedk > k calcedk k min = p_pointer+1 min p_pointer+1 p_pointer 1 elif p_pointer == max_weight or calck(all_w, p_pointer-1) > k:
        print(p_pointer)
        break
     p_pointer == max_weight or calck(all_w, p_pointer-1) > k p_pointer == max_weight p_pointer max_weight calck(all_w, p_pointer-1) > k calck(all_w, p_pointer-1) calck all_w p_pointer-1 p_pointer 1 k print(p_pointer) print p_pointer break max = p_pointer-1 max p_pointer-1 p_pointer 1 max = max, sum sum max p_pointer = (min+max)//2 (min+max)//2 p_pointer n, k =map(lambda x: int(x), input().split(' ')) map(lambda x: int(x), input().split(' ')) n max = -1 -1 max max_weight = max max max_weight calcedk = calck(all_w, p_pointer) calck(all_w, p_pointer) calcedk min = p_pointer+1 p_pointer+1 min max = w w max sum += w w sum all_w = [] [] all_w def calck(all_w, p):
    count = 0
    sum = 0
    for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
    return count+1

#get n and k def calck(all_w, p):
    count = 0
    sum = 0
    for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
    return count+1

#get n and k calck sum_weight = sum sum sum_weight k =map(lambda x: int(x), input().split(' ')) map(lambda x: int(x), input().split(' ')) k min, max = max, sum max min sum = 0 0 sum w = int(input()) int(input()) w max = p_pointer-1 p_pointer-1 max
#define k from p
def calck(all_w, p):
    count = 0
    sum = 0
    for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
    return count+1

#get n and k
n, k =map(lambda x: int(x), input().split(' '))

#get all w
#set min and max of p
all_w = []
max = -1
sum = 0
for i in range(n):
    w = int(input())
    all_w.append(w)
    if w > max:
        max = w
    sum += w
max_weight = max
sum_weight = sum
min, max = max, sum
#binary search of p

while min<=max:
    p_pointer = (min+max)//2
    calcedk = calck(all_w, p_pointer)
    if calcedk > k:
        min = p_pointer+1
    elif p_pointer == max_weight or calck(all_w, p_pointer-1) > k:
        print(p_pointer)
        break
    else:
        max = p_pointer-1
