#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, ans = INF;
	int p[4], t[4], dp[1100] = {};
	
	cin>>N;
	
	for(int i = 0; i < 4; i++){
		cin>>p[i];
	}
	for(int i = 0; i < 4; i++){
		cin>>t[i];
	}
	
	for(int i = 1; i < 1100; i++){
		dp[i] = INF;
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 1100; j++){
			if(dp[j] != INF){
				if(j+t[i] < 1100) dp[j+t[i]] = min(dp[j+t[i]], dp[j] + p[i]);
			}
		}
	}
	
	for(int i = N; i < 1100; i++){
		ans = min(ans, dp[i]);
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}
