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 ans = n;
        foreach (i; 0..n+1) {
            if (i > 0 && g1 >= g2) break;
            foreach (j; 0..n-i+1) {
                if (j > 0 && s1 >= s2) break;
                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;
                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;


}

