len, truck_cnt = gets.chomp.split(' ').map(&:to_i)
loads = readlines.map(&:chomp).map(&:to_i)

max_load = loads.max
avg_load_per_truck = loads.sum / truck_cnt
min_cap = max_load > avg_load_per_truck ? max_load : avg_load_per_truck
max_cap = max_load * len / truck_cnt + 1
# cap = (min_cap + max_cap) / 2
while true
  l_sum = 0
  truck_i = 1
  truck_overflow = false
  cap = (min_cap + max_cap) / 2
  loads.each do |l|
    if l_sum + l > cap
      truck_i += 1
      if truck_i > truck_cnt
        truck_overflow = true
        break
      end
      l_sum = l
    else
      l_sum += l
    end
  end
  if truck_overflow
    min_cap = cap + 1
  else
    max_cap = cap
  end
  break if min_cap == max_cap
end
puts min_cap
