#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>p(4);
    vector<int>t(4);
    rep(i,4)cin >> p[i];
    rep(i,4)cin >> t[i];
    int mi = inf;
    vector<int> dp(n+200,inf);
    dp[0] = 0;
    rep(i,4){
        for(int j=t[i];j<=n+100;j++){
            dp[j] = min(dp[j],dp[j-t[i]]+p[i]);
        }
        
    }
    
    for(int i=n;i<=n+101;i++){
        mi = min(mi,dp[i]);
    }
    cout << mi << endl;
    return 0;

}
