#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

ll solve(ll n, int w[3], int v[3]) {
	ll* dp[4];
	for (int i = 0; i < 4; i++)dp[i] = new ll[n + 1];
	for (int i = 0; i < n + 1; i++)dp[0][i] = i;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j <= n; j++) {
			if (j - w[i] >= 0) {
				dp[i + 1][j] = max(dp[i + 1][j - w[i]] + v[i], dp[i][j]);
			}
			else dp[i + 1][j] = dp[i][j];
		}
	}
	return dp[3][n];
}

int main() {
	while (cin >> N) {
		int a[3];
		int b[3];
		cin >> a[0] >> a[1] >> a[2];
		cin >> b[0] >> b[1] >> b[2];
		int v[3];
		N = solve(N, a, b);
		N = solve(N, b, a);
		cout << N << endl;
	}
}
