def stackable(pack, tmp_p, k):
  cur_w = 0
  trucks = 1
  for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

  return True

n, k = map(int, input().split())
pack = []

for i in range(n):
  pack.append(int(input()))

left = int(sum(pack) / k)
right = max(pack) * n

while left < right - 1:
  tmp_p = int((left + right) / 2)
  if stackable(pack, tmp_p, k):
    right = tmp_p
  else:
    left = tmp_p

if stackable(pack, left, k):
  print(left)
else:
  print(right) def stackable(pack, tmp_p, k):
  cur_w = 0
  trucks = 1
  for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

  return True stackable cur_w = 0 cur_w 0 trucks = 1 trucks 1 for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

   i range(len(pack)) range len(pack) len pack if tmp_p < pack[i]:
      return False

     tmp_p < pack[i] tmp_p pack[i] pack i return False False if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

   cur_w + pack[i] <= tmp_p cur_w + pack[i] cur_w pack[i] pack i tmp_p cur_w += pack[i] cur_w pack[i] pack i cur_w = pack[i] cur_w pack[i] pack i trucks += 1 trucks 1 if k < trucks:
        return False

   k < trucks k trucks return False False return True True pack pack tmp_p tmp_p k k n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k pack = [] pack [] for i in range(n):
  pack.append(int(input())) i range(n) range n pack.append(int(input())) pack.append pack append int(input()) int input() input left = int(sum(pack) / k) left int(sum(pack) / k) int sum(pack) / k sum(pack) sum pack k right = max(pack) * n right max(pack) * n max(pack) max pack n while left < right - 1:
  tmp_p = int((left + right) / 2)
  if stackable(pack, tmp_p, k):
    right = tmp_p
  else:
    left = tmp_p left < right - 1 left right - 1 right 1 tmp_p = int((left + right) / 2) tmp_p int((left + right) / 2) int (left + right) / 2 left + right left right 2 if stackable(pack, tmp_p, k):
    right = tmp_p
  else:
    left = tmp_p stackable(pack, tmp_p, k) stackable pack tmp_p k right = tmp_p right tmp_p left = tmp_p left tmp_p if stackable(pack, left, k):
  print(left)
else:
  print(right) stackable(pack, left, k) stackable pack left k print(left) print left print(right) print right left = tmp_p tmp_p left left = int(sum(pack) / k) int(sum(pack) / k) left def stackable(pack, tmp_p, k):
  cur_w = 0
  trucks = 1
  for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

  return True def stackable(pack, tmp_p, k):
  cur_w = 0
  trucks = 1
  for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

  return True stackable n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k right = tmp_p tmp_p right right = max(pack) * n max(pack) * n right tmp_p = int((left + right) / 2) int((left + right) / 2) tmp_p pack = [] [] pack
def stackable(pack, tmp_p, k):
  cur_w = 0
  trucks = 1
  for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

  return True

n, k = map(int, input().split())
pack = []

for i in range(n):
  pack.append(int(input()))

left = int(sum(pack) / k)
right = max(pack) * n

while left < right - 1:
  tmp_p = int((left + right) / 2)
  if stackable(pack, tmp_p, k):
    right = tmp_p
  else:
    left = tmp_p

if stackable(pack, left, k):
  print(left)
else:
  print(right)
