#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> a(3), b(3);
	rep(i,3) cin >> a[i];
	rep(i,3) cin >> b[i];
	rep(i,2){
		vector<ll> dp(n+1);
		rep(j,3)rep(k,n){
			if(k+a[j] <= n) chmax(dp[k+a[j]], dp[k] + b[j]);
		}
		ll score = 0;
		rep(j,n+1) chmax(score, n-j+dp[j]);
		n = score;
		swap(a, b);
	}
	cout << n << endl;
	return 0;
}