#include <bits/stdc++.h>

using namespace std;

void update(vector<long long> &f, long long n, int a, int b) {
	for (int i = a; i <= n; i++) {
		f[i] = max(f[i], f[i - a] + b);
	}
}

int main() {
	long long n, m;
	cin >> n;
	vector<int> a(3), b(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> b[i];
	}
	vector<long long> f;
	// A -> B
	f = vector<long long>(n + 1, 0);
	for (int i = 0; i < 3; i++) {
		if (a[i] < b[i]) {
			update(f, n, a[i], b[i]);
		}
	}
	m = 0;
	for (int i = n; i >= 0; i--) {
		m = max(f[i] + n - i, m);
	}
	n = m;
	// cout << n << endl;
	// B -> A
	f = vector<long long>(n + 1, 0);
	for (int i = 0; i < 3; i++) {
		if (a[i] > b[i]) {
			update(f, n, b[i], a[i]);
		}
	}
	m = 0;
	for (int i = n; i >= 0; i--) {
		m = max(f[i] + n - i, m);
	}
	cout << m << endl;
	return 0;
}