N, *CS = ARGF.read.lines.map(&:to_i)

def make_iterator initial, cs
  gen = 0
  ns = [ initial, 0, 0, 0, 0 ]
  Enumerator::new{ |y|
    loop {
      break   if ns.all?(&:zero?)
      y << [ gen, ns ]
      gen = gen + 1
      mvs = ([ 0 ] + ns.zip(cs).map(&:min)).each_cons(2)
      ns = ns.zip(mvs).map{ |n,io| n + io.first - io.last }
    }
  }
end



iterator = make_iterator(N, CS)

puts iterator.to_a.last.first + 1
