#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 6000*6000;

ll n, a1, a2, b1, b2, c1, c2;
ll ans;

ll dp[MAXN+10];

void solve()
{
    ll i, j;
    for(j=0; j<=n; j++) dp[j]=j;
    dp[0]=0;
    for(j=0; j<=n; j++)
    {
        if(a1<=j) dp[j]=max(dp[j], dp[j-a1]+a2);
        if(b1<=j) dp[j]=max(dp[j], dp[j-b1]+b2);
        if(c1<=j) dp[j]=max(dp[j], dp[j-c1]+c2);
    }
    ans=0;
    for(i=0; i<=n; i++) ans=max(ans, dp[i]);
}

int main()
{
    ll i, j, k;
    scanf("%lld%lld%lld%lld%lld%lld%lld", &n, &a1, &b1, &c1, &a2, &b2, &c2);

    solve();
    n=ans; swap(a1, a2); swap(b1, b2); swap(c1, c2);
    solve();

    printf("%lld", ans);
}
