#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
  int n;
  cin >> n;
  vector<int> a(4),b(4),c(n,inf);
  rep(i,4) cin >> a.at(i);
  rep(i,4) cin >> b.at(i);
  int ans=inf;
  c.at(0)=0;
  rep(i,4){
    for (int j=0;j<n;j++){
      if (c.at(j)==inf) continue;
      if (j+b.at(i)>=n) ans=min(ans,c.at(j)+a.at(i));
      else c.at(j+b.at(i))=c.at(j)+a.at(i);
    }
  }
  cout << ans << endl;
}

