module bbb;import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto N = readln.chomp.to!int;
    auto s = readln.split.map!(to!int);
    auto Ga = s[0];
    auto Sa = s[1];
    auto Ba = s[2];
    s = readln.split.map!(to!int);
    auto Gb = s[0];
    auto Sb = s[1];
    auto Bb = s[2];

    long solve(long n, long g1, long g2, long s1, long s2, long b1, long b2) {
        long[][] X;
        if (g1 < g2) X ~= [g1, g2];
        if (s1 < s2) X ~= [s1, s2];
        if (b1 < b2) X ~= [b1, b2];
        long ans = n;
        if (X.length == 0) return n;
        else if (X.length == 1) return n / X.front[0] * X.front[1] + n % X.front[0];
        else if (X.length == 2) {
            foreach (i; 0..n+1) {
                long j = n - i;
                long tmp = i / X[0][0] * X[0][1] + j / X[1][0] * X[1][1] + i % X[0][0] + j % X[1][0];
                ans = max(ans, tmp);
            }
        }
        else {
            foreach (i; 0..n+1) {
                foreach (j; 0..n-i+1) {
                    long k = n - i - j;
                    if (b1 >= b2) k = 0;
                    //long tmp = i / g1 * g2 + j / s1 * s2 + k / b1 * b2 + i % g1 + j % s1 + k % b1;
                    long tmp = i / X[0][0] * X[0][1] + j / X[1][0] * X[1][1] + k / X[2][0] * X[2][1] + i % X[0][0] + j % X[1][0] + k % X[2][0];
                    ans = max(ans, tmp);
                }
            }
        }
        return ans;
    }

    auto M = solve(N, Ga, Gb, Sa, Sb, Ba, Bb);
    auto L = solve(M, Gb, Ga, Sb, Sa, Bb, Ba);
    L.writeln;


}

