#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
int main(){
    int n;
    cin>>n;
    vector<int> a(3),b(3);
    for(auto & t : a) cin>>t;
    for(auto & t : b) cin>>t;
    ll ret = n;
    for(int i=0;i<2;++i){
        vector<ll> dp(ret+1);
        iota(dp.begin(),dp.end(),0);
        for(int j=0;j<3;++j){
            for(int k=0;k+a[j] <=ret;++k){
                dp[k+a[j]] = max(dp[k+a[j]],dp[k] + b[j]);
            }
        }
        ret = dp[ret];
        swap(a,b);
    }
    cout << ret << endl;
    return 0;
}

