#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
inline int power(int a, int b) {
int x = 1;
while (b) {
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}
const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;
//_ ***************************** START Below *******************************
vector<int> cost(3);
vector<int> amount(3);
vector<int> effect;
//* O(n^3)
void bruteforce(int n) {
int minCost = INF;
for(int i=0; i<=amount[0]; i++){
for(int j=0; j<=amount[1]; j++){
for(int k=0; k<=amount[2]; k++){
int net = i*effect[0] + j*effect[1] + k*effect[2];
if(net == n){
int totalCost = i*cost[0] + j*cost[1] + k*cost[2];
minCost = min(minCost, totalCost );
}
}
}
}
cout << minCost << endl;
}
// O(n^2)
void consistency(int n) {
int minCost = INF;
for(int i=0; i<=amount[0]; i++){
for(int j=0; j<=amount[1]; j++){
int k = (n - i*effect[0] - j*effect[1] ) / effect[2];
if(k>=0 && k<= amount[2]){
int net = i*effect[0] + j*effect[1] + k*effect[2];
if(net == n){
int totalCost = i*cost[0] + j*cost[1] + k*cost[2];
minCost = min(minCost, totalCost );
}
}
}
}
cout << minCost << endl;
}
void solve() {
int n;
cin >> n;
effect = {2, 3, 5};
for(int i=0; i<3; i++) cin >> amount[i];
for(int i=0; i<3; i++) cin >> cost[i];
bruteforce(n);
consistency(n) ;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}