// D - Squirrel Merchant
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<int> a(3), b(3), v(3);
	for (int i = 0; i < 3; i++) cin >> a[i];
	for (int i = 0; i < 3; i++) cin >> b[i];

	vector<long long> dp(n + 1);
	for (int i = 0; i < 3; i++) v[i] = b[i] - a[i];
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < 3; j++)
			if (a[j] <= i) dp[i] = max(dp[i], dp[i - a[j]] + v[j]);

	int m = dp[n] + n;
	dp.assign(m + 1, 0);
	for (int i = 0; i < 3; i++) v[i] = a[i] - b[i];
	for (int i = 0; i <= m; i++)
		for (int j = 0; j < 3; j++)
			if (b[j] <= i) dp[i] = max(dp[i], dp[i - b[j]] + v[j]);

	cout << (dp[m] + m) << endl;
	return 0;
}
