#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N;
ll a[3];
ll b[3];

ll func(vector<ll>& AtoB, ll N, ll *a, ll *b) {
  if (len(AtoB) == 1) {
    ll i = AtoB[i];
    ll g = (N/a[i]);
    N -= g*a[i];
    N += g*b[i];
  } else if (len(AtoB) == 2) {
    ll ma = 0;
    for (ll n = 0; n <= N; ++n) {
      ll m = N-n;
      ll tmp = N;
      ll i = AtoB[0], j = AtoB[1];
      ll g = (n/a[i]);
      ll s = (m/a[j]);
      tmp -= g*a[i] + s*a[j];
      tmp += g*b[i] + s*b[j];
      ma = max(ma, tmp);
    }
    N = ma;
  } else if (len(AtoB) == 3) {
    ll ma = 0;
    for (ll n = 0; n <= N; ++n) {
      for (ll m = 0; m <= (N-n); ++m) {
        ll l = (N-m-n);
        ll tmp = N;
        ll i = AtoB[0], j = AtoB[1], k = AtoB[2];
        ll g = (n/a[i]);
        ll s = (m/a[j]);
        ll br = (l/a[k]);
        tmp -= g*a[i] + s*a[j] + br*a[k];
        tmp += g*b[i] + s*b[j] + br*b[k];
        ma = max(ma, tmp);
      }
    }
    N = ma;
  }

  return N;
}

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);

  cin >> N;
  cin >> a[0] >> a[1] >> a[2];
  cin >> b[0] >> b[1] >> b[2];

  vector<ll> AtoB, BtoA;
  if (a[0] < b[0]) AtoB.push_back(0);
  if (a[0] > b[0]) BtoA.push_back(0);
  if (a[1] < b[1]) AtoB.push_back(1);
  if (a[1] > b[1]) BtoA.push_back(1);
  if (a[2] < b[2]) AtoB.push_back(2);
  if (a[2] > b[2]) BtoA.push_back(2);

  N = func(AtoB, N, a, b);
  N = func(BtoA, N, b, a);

  cout << N << endl;

  return 0;
  /*
  if (len(AtoB) == 1) {
    int i = AtoB[i];
    int g = (N/a[i]);
    N -= g*a[i];
    N += g*b[i];
  } else if (len(AtoB) == 2) {
    int ma = 0;
    for (int n = 0; n <= N; ++n) {
      int m = N-n;
      int tmp = N;
      int i = AtoB[0], j = AtoB[1];
      int g = (n/a[i]);
      int s = (m/a[j]);
      tmp -= g*a[i] + s*a[j];
      tmp += g*b[i] + s*b[j];
      ma = max(ma, tmp);
    }
    N = ma;
  } else if (len(AtoB) == 3) {
    int ma = 0;
    for (int n = 0; n <= N; ++n) {
      for (int m = 0; m <= (N-n); ++m) {
        int l = (N-m-n);
        int tmp = N;
        int i = AtoB[0], j = AtoB[1], k = AtoB[2];
        int g = (n/a[i]);
        int s = (m/a[j]);
        int br = (l/a[k]);
        tmp -= g*a[i] + s*a[j] + br*a[k];
        tmp += g*b[i] + s*b[j] + br*b[k];
        ma = max(ma, tmp);
      }
    }
    N = ma;
  }
  */
}


Measured memory_bytes: 256