number_of_packages, number_of_trucks = gets.split.map(&:to_i)

packages = $stdin.readlines.map(&:to_i)

check = lambda do |capacity|
  package_pos = 0

  0.upto(number_of_trucks - 1) do |j|
    weight = 0

    while weight + packages[package_pos] <= capacity
      weight += packages[package_pos]
      package_pos += 1

      return number_of_packages if package_pos == number_of_packages
    end
  end

  return package_pos
end

left = 0
right = 100000 * 10000

while right - left > 1
  mid = (left + right) / 2

  v = check.call(mid)

  if v >= number_of_packages
    right = mid
  else
    left = mid
  end
end

puts right