#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


struct Napsack_multiok{
    int C;//容量
    int N;//商品数
    pair<int,int> *prods;//(容積、価値)
    int *dp;//dp[N][C]:dp[x][y]容積をy使ってxまでの商品で埋めた時の最大
    int prod_count; 
    Napsack_multiok(int c,int n): C(c),N(n){ //make table
        prods = new pair<int,int>[N];
        prod_count=0;
        dp = new int[(C+2)*(N+2)];
    }
    void initdp(){
        rep(i,C+1){
            rep(j,N+1){
                dp[mkitr(i,j)]=0;
            }
        }
    }
    int mkitr(int x,int y){
        return x*(C+1)+y;
    }
    void push_prods(int c,int p){//(容積、価値)
        prods[prod_count++]=mp(c,p);
    }
    int solve(){//価値の最大値を返す。
        initdp();
        rep(i,N+1){
            if(i>0)rep(j,C+1){
                dp[mkitr(i,j)]=dp[mkitr(i-1,j)];
                if(j>0)dp[mkitr(i,j)]=max(dp[mkitr(i,j)],dp[mkitr(i,j-1)]);
                int p=prods[i-1].second;int c=prods[i-1].first;
                if(j-c>=0)dp[mkitr(i,j)]=max(dp[mkitr(i,j)],dp[mkitr(i,j-c)]+p);
            }
        }
        return dp[mkitr(N,C)];
    }
    void debug_printdp(){
        rep(i,N+1){
            rep(j,C+1){printf("%lld ",dp[mkitr(i,j)]);}
            printf("\n");
        }
    }
    void free_(){
        delete[] prods;
        delete[] dp;
    }
    
};

int N_input;
int ga,sa,ba,gb,sb,bb;
int ans=0;
signed main(){
    scanf("%lld",&N_input);
    scanf("%lld %lld %lld",&ga,&sa,&ba);
    scanf("%lld %lld %lld",&gb,&sb,&bb);
    //(a)(c)
    Napsack_multiok AC(N_input,3);
    AC.push_prods(ga,gb-ga);AC.push_prods(sa,sb-sa);AC.push_prods(ba,bb-ba);
    int M=AC.solve()+N_input;
    AC.free_();
    Napsack_multiok BD(M,3);
    BD.push_prods(gb,ga-gb);BD.push_prods(sb,sa-sb);BD.push_prods(bb,ba-bb);
    ans=BD.solve()+M;
    printf("%lld\n",ans);
    BD.free_();
}
