#include <bits/stdc++.h>

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[10][201];

signed main(){
    int N; cin >> N;
    vector<int> p( 4 ), t( 4 );
    REP( i, 4 ) cin >> p[i];
    REP( i, 4 ) cin >> t[i];

    fill( dp[0], dp[4], INF );
    REP( i, 4 ) dp[i][0] = 0;
    REP( i, 4 ) dp[0][t[i]] = p[i];

    REP( i, 4 ){
        REP( j, 201 ){
            if( j < t[i] ){
                dp[i + 1][j] = dp[i][j];
            }else{
                dp[i + 1][j] = min( dp[i][j], dp[i + 1][j - t[i]] + p[i] );
            }
        }
    }


    int ans = INF;
    FOR( i, N, 201 ){
        chmin( ans, dp[4][i] );
    }

    cout << ans << endl;
}

