#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};




int main(){
    LL N;cin >> N;
    LL pa,pb,pc,pd;cin >> pa >> pb >> pc >> pd;
    LL ta,tb,tc,td;cin >> ta >> tb >> tc >> td;
    LL ans = 1e18;
    for(int i = 0;i <= N;i++){
        for(int j = 0;j <= N;j++){
            for(int k = 0;k <= N;k++){
                for(int l = 0;l <= N;l++){
                    LL sum = ta * i + tb * j + tc *k + l * td;
                    if(sum >= N){
                        ans = min(ans, pa * i + pb * j + pc * k + pd * l);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

