#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N;
int ga, sa, ba, gb, sb, bb;

int solve(int n) {
    int dp[n+1];
    rep(i, n+1) dp[i] = i;
    rep(i, n+1) {
        if (i-ga>=0) dp[i] = max(dp[i], dp[i-ga]+gb);
        if (i-sa>=0) dp[i] = max(dp[i], dp[i-sa]+sb);
        if (i-ba>=0) dp[i] = max(dp[i], dp[i-ba]+bb);
    }
    return dp[n];
}

signed main() {
    cin >> N >> ga >> sa >> ba >> gb >> sb >> bb;
    int M = solve(N);
    swap(ga, gb);
    swap(sa, sb);
    swap(ba, bb);
    cout << solve(M);
}