#include<bits/stdc++.h>

using namespace std;

int main(void) {
    long n;
    cin >> n;
    vector<long> a(3);
    for(auto &x: a) cin >> x;
    vector<long> b(3);
    for(auto &x: b) cin >> x;

    {
        vector<long> dp(n+1);
        for(long i=0; i<n; i++) {
            dp[i+1] = max(dp[i+1], dp[i]+1);
            for(long j=0; j<3; j++)
                if(i+a[j] <= n)
                    dp[i+a[j]] = max(dp[i+a[j]], dp[i] + b[j]);
        }
        n = dp[n];
    }

    {
        vector<long> dp(n+1);
        for(long i=0; i<n; i++) {
            dp[i+1] = max(dp[i+1], dp[i]+1);
            for(long j=0; j<3; j++)
                if(i+b[j] <= n)
                    dp[i+b[j]] = max(dp[i+b[j]], dp[i] + a[j]);
        }
        n = dp[n];
    }

    cout << n << endl;
}
