N = STDIN.gets.chomp.to_i

transportation = []
city = [N,0,0,0,0,0]

5.times do
  transportation  << STDIN.gets.chomp.to_i
end

current_time = 0

while true
  current_time += 1

  transportation.each_with_index.reverse_each do |v, i|
    unless city[i].zero?
      if (city[i] - v) < 0
        city[i+1] += city[i]
        city[i] = 0
      else
        city[i] -= v
        city[i+1] += v
      end
    end
  end

  break if city.last == N
end

puts current_time
