def num_packs(p)
  i = 0
  @k.times do
    s = 0
    loop do
      break if i == @n
      break if s + @w[i] > p
      s += @w[i]
      i += 1
    end
    break if i == @n
  end
  i
end

def bsearch(min, max)
  return min if min == max

  half = (max - min) / 2 + min
  if num_packs(half) < @n
    bsearch(half+1, max)
  else
    bsearch(min, half)
  end
end


@n, @k = gets.split.map(&:to_i)
@w = []
max = 0
@n.times do
  w = gets.to_i
  max = [max, w].max
  @w << w
end
p_min, p_max = 0, max
while num_packs(p_max) < @n
  p_min = p_max
  p_max = p_max * 2
end
puts bsearch(p_min, p_max)
