N = gets.to_i
rates = (0..1).map{ gets.split.map &:to_i }.transpose
rates.sort_by!{ |a,b| -a.to_f/b.to_f  }

G,S,B = rates
if rates.count{ |a,b| a.to_f/b.to_f <= 1 } == 3
  $stderr.puts "A"
  m = N%B[0]
  r = m%S[0]
  p N/B[0]*B[1]+m/S[0]*S[1]+r/G[0]*G[1]+r%G[0]
elsif rates.count{ |a,b| a.to_f/b.to_f >= 1 } == 3 
  $stderr.puts "B"
  m = N%B[1]
  r = m%S[1]
  p N/B[1]*B[0]+m/S[1]*S[0]+r/G[1]*G[0]+r%G[1]
elsif rates.count{ |a,b| a.to_f/b.to_f >= 1 } == 2
  $stderr.puts "C"
  r = N%B[0]
  n = N/B[0]*B[1]
  ans = 0
  (0..n/G[1]).each{ |m0|
    m = m0*G[1]
    ans = [ans, m/G[1]*G[0] + [(n-m+r)/S[1]*S[0] + (n-m+r) % S[1], n-m+r].max].max
  }
  p ans
else
  $stderr.puts "D"
  ans = 0
  r = N%S[0]
  (0..N/S[0]).each{ |m0|
    n = N
    m = m0*S[0]
    ds = [m/S[0]*S[1], m].max
    db = [(n-m)/B[0]*B[1] + (n-m)%B[0], n-m].max
    d = [(ds+db)/G[1]*G[0] + (ds+db)%G[1], ds+db].max + r
    ans = [ans, d].max
  }
  p ans
end
