n = gets.to_i
rra = gets.split(' ').map(&:to_i)
ra = { g: rra[0], s: rra[1], b: rra[2] }
rrb = gets.split(' ').map(&:to_i)
rb = { g: rrb[0], s: rrb[1], b: rrb[2] }

w = { g: 0, s: 0, b: 0 }

[:g, :s, :b].select {|t| ra[t] < rb[t] }.sort_by {|t| 1.0 * ra[t] / rb[t] }.each {|t|
  c = n / ra[t]
  w[t] += c
  n -= ra[t] * c
}

[:g, :s, :b].each {|t|
  n += w[t] * rb[t]
  w[t] = 0
}

[:g, :s, :b].select {|t| rb[t] < ra[t] }.sort_by {|t| 1.0 * rb[t] / ra[t] }.each {|t|
  c = n / rb[t]
  w[t] += c
  n -= rb[t] * c
}

[:g, :s, :b].each {|t|
  n += w[t] * ra[t]
  w[t] = 0
}

puts n
