#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=30000010;
int n,a[2][3];
ll f[N];

ll solve(int x,int y,int n){
	rep(i,0,n) f[i]=i;
	rep(i,0,2) rep(j,a[x][i],n) f[j]=max(f[j],f[j-a[x][i]]+a[y][i]);
	return f[n];
}

int main(){
	scanf("%d",&n);
	rep(i,0,1) rep(j,0,2) scanf("%d",&a[i][j]);
	printf("%lld\n",solve(1,0,solve(0,1,n)));
	return 0;
}