#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




long long N;
long long a[3], b[3];

long long calc(vector<long long> sei, vector<long long> obj, long long M) {
    if (sei.size() == 0) return M;
    if (sei.size() == 1) {
        long long rem = M;
        long long p = rem / sei[0];
        long long r = rem % sei[0];
        return p * obj[0] + r;
    }
    if (sei.size() == 2) {
        long long res = M;
        long long rx, ry;
        for (long long x = 0; x * sei[0] <= M; ++x) {
            long long rem = M - x * sei[0];
            long long p = rem / sei[1];
            long long r = rem % sei[1];
            if (chmax(res, x * obj[0] + p * obj[1] + r)) {
                rx = x;
                ry = p;
            }
        }

        /*
        COUT(sei);
        COUT(obj);
        COUT(M);
        COUT(res);
        COUT(rx);
        COUT(ry);
        */
        return res;
    }
    if (sei.size() == 3) {
        long long res = M;
        long long rx, ry, rz;
        for (long long x = 0; x * sei[0] <= M; ++x) {
            for (long long y = 0; x * sei[0] + y * sei[1] <= M; ++y) {
                long long rem = M - x * sei[0] - y * sei[1];
                long long p = rem / sei[2];
                long long r = rem % sei[2];
                if (chmax(res, x * obj[0] + y * obj[1] + p * obj[2] + r)) {
                    rx = x, ry = y, rz = p;
                }
            }
        }

        /*
        COUT(sei);
        COUT(obj);
        COUT(M);
        COUT(res);
        COUT(rx);
        COUT(ry);
        COUT(rz);
        */
        return res;
    }
    return M;
}

long long solve() {
    // zenhan
    {
        vector<long long> sei, obj;
        for (int i = 0; i < 3; ++i) {
            if (a[i] < b[i]) {
                sei.push_back(a[i]);
                obj.push_back(b[i]);
            }
        }
        N = calc(sei, obj, N);
    }

    // kouhan
    {
        vector<long long> sei, obj;
        for (int i = 0; i < 3; ++i) {
            if (a[i] > b[i]) {
                sei.push_back(b[i]);
                obj.push_back(a[i]);
            }
        }
        N = calc(sei, obj, N);
    }
    return N;
}

int main() {
    while (cin >> N) {
        for (int i = 0; i < 3; ++i) cin >> a[i];
        for (int i = 0; i < 3; ++i) cin >> b[i];
        cout << solve() << endl;
    }
}















Measured memory_bytes: 256