//Δ_D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 5005;
const int M = N*N;
int n,a[3],b[3];
LL f[M];
int main()
{
	int i,j;
	LL o;
	cin>>n;
	for(i=0;i<3;i=i+1)
		cin>>a[i];
	for(i=0;i<3;i=i+1)
		cin>>b[i];
	memset(f,0,sizeof(f));
	for(i=0;i<3;i=i+1)
		for(j=a[i];j<=n;j=j+1)
			f[j]=max(f[j],f[j-a[i]]+b[i]);
	o=0;
	for(i=0;i<=n;i=i+1)
		o=max(o,f[i]+n-i);
	n=o;
	memset(f,0,sizeof(f));
	for(i=0;i<3;i=i+1)
		for(j=b[i];j<=n;j=j+1)
			f[j]=max(f[j],f[j-b[i]]+a[i]);
	o=0;
	for(i=0;i<=n;i=i+1)
		o=max(o,f[i]+n-i);
	cout<<o;
	return 0;
}