import math

p_max = 1000000 * 1000000
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]

def check(p):
  i = 0
  for j in range(k):
    s = 0
    while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
  return i

if __name__ == "__main__":
  right = p_max
  left = 0
  mid = 0
  while (right - left > 1):
    mid = math.floor((right + left) / 2)
    v = check(mid)
    if v >= n:
      right = mid
    else:
      left = mid
  
  print (right) import math math p_max = 1000000 * 1000000 p_max 1000000 * 1000000 1000000 1000000 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 w = [int(input()) for i in range(n)] w [int(input()) for i in range(n)] def check(p):
  i = 0
  for j in range(k):
    s = 0
    while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
  return i check i = 0 i 0 for j in range(k):
    s = 0
    while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
   j range(k) range k s = 0 s 0 while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
   s + w[i] <= p s + w[i] s w[i] w i p s += w[i] s w[i] w i i += 1 i 1 if i == n:
        return n
   i == n i n return n n return i i p p if __name__ == "__main__":
  right = p_max
  left = 0
  mid = 0
  while (right - left > 1):
    mid = math.floor((right + left) / 2)
    v = check(mid)
    if v >= n:
      right = mid
    else:
      left = mid
  
  print (right) __name__ == "__main__" __name__ "__main__" right = p_max right p_max left = 0 left 0 mid = 0 mid 0 while (right - left > 1):
    mid = math.floor((right + left) / 2)
    v = check(mid)
    if v >= n:
      right = mid
    else:
      left = mid
  
   right - left > 1 right - left right left 1 mid = math.floor((right + left) / 2) mid math.floor((right + left) / 2) math.floor math floor (right + left) / 2 right + left right left 2 v = check(mid) v check(mid) check mid if v >= n:
      right = mid
    else:
      left = mid
  
   v >= n v n right = mid right mid left = mid left mid print (right) print right right = p_max p_max right n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k left = mid mid left mid = 0 0 mid mid = math.floor((right + left) / 2) math.floor((right + left) / 2) mid w = [int(input()) for i in range(n)] [int(input()) for i in range(n)] w left = 0 0 left def check(p):
  i = 0
  for j in range(k):
    s = 0
    while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
  return i def check(p):
  i = 0
  for j in range(k):
    s = 0
    while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
  return i check p_max = 1000000 * 1000000 1000000 * 1000000 p_max right = mid mid right v = check(mid) check(mid) v
import math

p_max = 1000000 * 1000000
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]

def check(p):
  i = 0
  for j in range(k):
    s = 0
    while (s + w[i] <= p):
      s += w[i]
      i += 1
      if i == n:
        return n
  return i

if __name__ == "__main__":
  right = p_max
  left = 0
  mid = 0
  while (right - left > 1):
    mid = math.floor((right + left) / 2)
    v = check(mid)
    if v >= n:
      right = mid
    else:
      left = mid
  
  print (right)
