i = gets.to_i
ag, as, ab = gets.split.map(&:to_i)
bg, bs, bb = gets.split.map(&:to_i)
list =[]
list << i * ag * bg
list << i * as * ab
list << i * ab * bb
list << i * ag * ag
list << i * as * as
list << i * ab * ab

puts list.max