#include <bits/stdc++.h>
using namespace std;

using ll = long long;

struct S {
    int a, b;
};

ll f(ll x, vector<S> v) {
    v.erase(remove_if(v.begin(), v.end(),
        [](S s) { return s.a >= s.b; }
    ), v.end());

    if (v.empty())
        return x;

    int a = v[0].a, b = v[0].b;
    v.erase(v.begin());

    if (v.empty())
        return (x / a) * b + x % a;

    ll res = 0;
    for (ll i = 0; i * a <= x; i++)
        res = max(res, i * b + f(x - i * a, v));

    return res;
}

int main() {
    int n;
    cin >> n;

    vector<S> v(3);
    for (int i = 0; i < 3; i++)
        cin >> v[i].a;
    for (int i = 0; i < 3; i++)
        cin >> v[i].b;

    vector<S> vr(3);
    for (int i = 0; i < 3; i++)
        vr[i] = {v[i].b, v[i].a};

    cout << f(f(n, v), vr) << endl;
}
