#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N, A[3], B[3];

int main() {
	cin >> N;
	for (int i = 0; i < 3; ++i) {
		cin >> A[i];
	}
	for (int i = 0; i < 3; ++i) {
		cin >> B[i];
	}
	vector<ll>v(N + 1, 0);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			if (A[j] < B[j] && i + A[j] <= N) {
				v[i + A[j]] = max(v[i + A[j]], v[i] + B[j]);
			}
		}
	}
	ll M = 0;
	for (int i = 0; i <= N; ++i) {
		M = max(M, v[i] + N - i);
	}
	v = vector<ll>(M + 1, 0);
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < 3; ++j) {
			if (B[j] < A[j] && i + B[j] <= M) {
				v[i + B[j]] = max(v[i + B[j]], v[i] + A[j]);
			}
		}
	}
	for (int i = 0; i <= M; ++i) {
		N = max(N, v[i] + M - i);
	}
	cout << N << endl;
}