#! /usr/bin/ruby

n=gets.to_i
pa,pb,pc,pd=gets.chomp.split.map(&:to_i)
ta,tb,tc,td=gets.chomp.split.map(&:to_i)
ans=10**6;
0.step(101,1)do |a|
    0.step(101,1)do |b|
        0.step(101,1)do |c|
            if(n-(a*ta+b*tb+c*tc)<=0)then
                d=0
            else
                d=(n-(a*ta+b*tb+c*tc)+td-1)/td
            end

            ans=[ans,a*pa+b*pb+c*pc+d*pd].min
        end
    end
end
puts(ans)
