#include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;
const int INF = (int)1e8;

signed main(){
	int n; cin >> n;
	vector<int> p(4), t(4);
	for(auto &&e : p)cin >> e;
	for(auto &&e : t) cin >> e;
	
	vector<int> dp(n+1, INF);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 4; j++){
			if( i - t[j] < 0){
				dp[i] = min(dp[i], dp[0] + p[j]);
			}
			else{
				dp[i] = min(dp[i], dp[i-t[j]] + p[j]);
			}
		}
	}
	cout << dp.back() << endl;

	return 0;
}


