# coding: utf-8
# Here your code !
n,k=map(int,input().split())

weight=[int(input()) for i in range(n)]
def binary_search(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
    return left
 
def simulate(prb,wei,num):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
    return True
 
print(binary_search(max(weight), sum(weight))) n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input weight=[int(input()) for i in range(n)] weight [int(input()) for i in range(n)] def binary_search(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
    return left
  binary_search left = start left start right = end right end middle = 0 middle 0 while left < right:
        middle = (left + right)//2
        if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
     left < right left right middle = (left + right)//2 middle (left + right)//2 left + right left right 2 if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
     simulate(middle,weight,k) simulate middle weight k right = middle right middle left = middle + 1 left middle + 1 middle 1 return left left start start end end def simulate(prb,wei,num):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
    return True
  simulate count = 1 count 1 tmp = 0 tmp 0 for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
     j wei tmp += j tmp j if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
     tmp > prb tmp prb tmp = j tmp j count += 1 count 1 if count > num:
                return False
     count > num count num return False False return True True prb prb wei wei num num print(binary_search(max(weight), sum(weight))) print binary_search(max(weight), sum(weight)) binary_search max(weight) max weight sum(weight) sum weight weight=[int(input()) for i in range(n)] [int(input()) for i in range(n)] weight def binary_search(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
    return left
  def binary_search(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
    return left
  binary_search k=map(int,input().split()) map(int,input().split()) k n,k=map(int,input().split()) map(int,input().split()) n def simulate(prb,wei,num):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
    return True
  def simulate(prb,wei,num):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
    return True
  simulate
# coding: utf-8
# Here your code !
n,k=map(int,input().split())

weight=[int(input()) for i in range(n)]
def binary_search(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,weight,k):
            right = middle
        else:
            left = middle + 1
    return left
 
def simulate(prb,wei,num):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > num:
                return False
    return True
 
print(binary_search(max(weight), sum(weight)))