n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

k = [b, a].transpose.map { |ele| 
ele.map(&:to_f).inject(:/) 
}
t = 0
s = 0
k.sort.reverse.each do |i|
    if (n > 0)
        s += (n / a[k.index(i)]) * b[k.index(i)]
        n -= (n / a[k.index(i)]) * a[k.index(i)] 
    else 
        break
    end
end
p s