#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MOD = 1000000007;

long exp_mod(long long a, long long b, long m) {
	long long res = 1;
	while (b > 0) {
		if (b&1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}
	return (long)res;
}

long fact_mod(long n, long m) {
	long long res = 1;
	for (long i=n; i>0; --i)
		res = (res * i)%m;
	return (long)res;
}

long comb_mod(long n, long r) {
	long long res = 1;
	for (long i=0; i<r; ++i)
		res = (res * (n - i) )%MOD;
	return ( res * exp_mod(fact_mod(r, MOD), MOD-2, MOD) ) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

struct Pony
{
    int x,y;

    Pony(int x_, int y_)
    {
        x = x_;
        y = y_;
    }

    bool operator<(const Pony &another) const
    {
        return x < another.x;
    };
};

long modinv(long a, long m) {
    long b = m, u = 1, v = 0;
    while (b) {
        long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long n;

long g = 0;
long s = 0;
long b = 0;

void toG(int rate) {
  while(true) {
    if (n >= rate) {
      n -= rate;
      g++;
    } else {
      break;
    }
  }
}

void toS(int rate) {
  while(true) {
    if (n >= rate) {
      n -= rate;
      s++;
    } else {
      break;
    }
  }
}

void toB(int rate) {
  while(true) {
    if (n >= rate) {
      n -= rate;
      b++;
    } else {
      break;
    }
  }
}

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


  cin >> n;

  int ga, sa, ba;

  cin >> ga >> sa >> ba;

  int gb, sb, bb;

  cin >> gb >> sb >> bb;

  // at A

  long dp[25000001];
  rep(i, 25000001) dp[i] = i;

  int w[3];
  w[0] = ga;
  w[1] = sa;
  w[2] = ba;

  int v[3];
  v[0] = gb;
  v[1] = sb;
  v[2] = bb;

  for (int i = 0; i < 3; i++) {
    for (int j = w[i]; j <= n; j++) {
      dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
    }
  }

  n = dp[n];

  rep(i, 25000001) dp[i] = i;

  w[0] = gb;
  w[1] = sb;
  w[2] = bb;
  
  v[0] = ga;
  v[1] = sa;
  v[2] = ba;

  for (int i = 0; i < 3; i++) {
    for (int j = w[i]; j <= n; j++) {
      dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
    }
  }

  n = dp[n];

  // at B
  cout << n << endl; 
}



Measured memory_bytes: 195584