#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const 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;

	ll a[3];
	rep(i, 3) cin >> a[i];

	ll b[3];
	rep(i, 3) cin >> b[i];

	ll dp[n+1];
	rep(i, 4) rep(j, n+1) dp[j] = 0;
	dp[0] = n;
	
	rep(i, 3){
		rep(j, n+1) {
			if(j-a[i] >= 0) chmax(dp[j], dp[j-a[i]] + b[i] - a[i]); 
		}
	}

	ll m = 0;
	rep(j, n+1) chmax(m, dp[j]);

	vector<ll> dp2(m+1, 0);
	dp2[0] = m;

	rep(i, 3){
		rep(j, m+1){
			if(j-b[i] >= 0) chmax(dp2[j], dp2[j-b[i]] + a[i] - b[i]);
		}
	}

	ll ans = 0;
	rep(j, m+1) chmax(ans, dp2[j]);
	cout << ans << endl;
}
