//	Totally unrelated and not AT ALL stolen from hohohaha's template
#include <bits/stdc++.h>
using namespace std;
#define arctan atan
#define arccos acos
#define arcsin asin
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define vt vector
#define pr pair
#define Ahhhhhhhh		 "It's_ca_khia_Tham_:))"	// Rewind 2018 reference
#define Le_Minh_Tam		 "xinh"// though, a define is not needed.
#define Hoang_Duong		 "AC_10e69+7_bai_A_in_orz_minutes"
#define Andy_Duke_Anh	 "*Fantasie_Impromptu_100*"
#define Le_Phuc_Vinh	 "*T_dang_dung_check-pat*"
#define Kat_Bongo 		 "***Best_Python_Sniper***"
#define Chau_Vu	  		 "**SupaKHUNG_va_hoicham**"	// also very god of dp (yes, you read that right)
#define ZaP_zU	  		 "***Sieu_khung_va_orz***"	// also Asian tourist
#define Grey_rabbit		 "****Khung_ko_kem_ai****"
#define Pham_Hoang_Hiep	 "a.k.a_LuuNgocThaiSon-orz"
#define DTNhat_Long		 "***Bacc-tracc-ing_God***"
#define Nguyen_Nhat_Minh "**khungkhungkhungkhung**"	// I mean, there's not
#define Pham_Truong_Dat	 "orz_orz_ORZ!!!!!!!!!!!!!"	// much to say about
#define Duong_Minh_Khoi  "****don_thuan_la_ORZ****"	// these three people
#define Ta_Xuan_Duy  	 "*sieudepzainhungkokhung*"
#define Hachi_Minh		 "..." // yes, I haven't thought of one yet.  "F"s in the chat bois.
#define Lan_Leeeeee		 "Lan_le_bo_toai,_get_it??" // No? Ok fine that was smol pp joke on my part.
#define Chui_Minh_Hiu	 "Game_it_thoi"
#define endl			 "\n"
//	Disscliamer:  	- I do not know how to spell "Disclaimer" (thanks google for the correct spelling)
//					- Also, as stated by no laws that I can tell, the previous sentences are written for
//					the sake of "ca_khia"-ing. To the people mentioned in these sentences, the sentences
//					may not represent you as a person (though I do think that I'm pretty handsome myself)
//					and should not be taken as neither the truth, nor a personal attacc. Pls, no bulli.
//	Can't belive I spent 20+ lines and 6+ hours to do this. Oh well,
//	Until next time, remember:
//			You are closer, than you think.

template<typename float_t>	// for some reason, this is wayyyyy faster than std::complex;
struct _complex_ {			// and yes, I googled this.
    float_t x, y;

    _complex_<float_t>(float_t _x = 0, float_t _y = 0) : x(_x), y(_y) {}

    float_t real() const {
        return x;
    }

    void real(float_t _x) {
        x = _x;
    }

    float_t imag() const {
        return y;
    }

    void imag(float_t _y) {
        y = _y;
    }

    _complex_<float_t>& operator+=(const _complex_<float_t> &other) {
        x += other.x;
        y += other.y;
        return *this;
    }

    _complex_<float_t>& operator-=(const _complex_<float_t> &other) {
        x -= other.x;
        y -= other.y;
        return *this;
    }

    _complex_<float_t> operator+(const _complex_<float_t> &other) const {
        return _complex_<float_t>(*this) += other;
    }

    _complex_<float_t> operator-(const _complex_<float_t> &other) const {
        return _complex_<float_t>(*this) -= other;
    }

    _complex_<float_t> operator*(const _complex_<float_t> &other) const {
        return {x * other.x - y * other.y, x * other.y + other.x * y};
    }

    _complex_<float_t> operator*(float_t mult) const {
        return {x * mult, y * mult};
    }
    
    _complex_<float_t> operator/(const _complex_<float_t> &other) const {
        return {(((x * other.x) + (y * other.y)) / ((pow(other.x, 2.0)) + (pow(other.y, 2.0)))), 
				(((other.x * y) - (x * other.y)) / ((pow(other.x, 2.0)) + (pow(other.x, 2.0)))) };
    }
};

template<typename float_t>
_complex_<float_t> conj(const _complex_<float_t> &c) {
    return {c.x, -c.y};
}

template<typename float_t>
_complex_<float_t> polar(float_t magnitude, float_t angle) {
    return {magnitude * cos(angle), magnitude * sin(angle)};
}

template<typename float_t>
ostream& operator<<(ostream &stream, const _complex_<float_t> &c) {
    return stream << '(' << c.x << ", " << c.y << ')';
}

typedef double db;			typedef long long li;		typedef long double ld;			typedef string str;
typedef pr<int, int> ii;	typedef pr<li,li> ll;		typedef pr<ld,ld> dd;
typedef vt<int> vi;			typedef vt<li> vli;			typedef vt<bool> vb;
typedef vt<str> vs;			typedef vt<ii> vii;			typedef vt<ll> vll;
typedef map<int, int> mii;	typedef map<int, bool> mib;	typedef map<int, str> mis;		typedef map<int, char> mic;
typedef set<int> s_i;		typedef set<char> s_c;		typedef set<str> s_s;
typedef complex<db> cpx;	typedef vt<cpx> vcpx;

const int mod = 1e9+7;		const li inf = 9223372036854775807;
#define pi 3.1415926535897932		//  this is also faster than pi = acos(-1);
//	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.txt","r",stdin);

li n;
int a[3][2];

void sol(int pos)
{
	li dp[n+1];
	for(int i = 0; i < n+1; ++i) dp[i] = 0;
	for(int i = 0; i < n+1; ++i)
	{
		for(int j = 0; j < 3; ++j)
		{
			if (a[j][pos] < i+1)
			{
				dp[i] = max(dp[i], dp[i - a[j][pos]] + (a[j][(!pos)] - a[j][pos]) );
			}
		}
	}
	n += dp[n];
}

void solve()
{
	for (int j = 0; j < 2; ++j) for(int i = 0; i < 3; ++i) cin >> a[i][j];
	for (int j = 0; j < 2; ++j) sol(j);
}

signed main()
{
	cin  >> n;
	solve();
	cout << n;
    return 0;
}
// with the aura of Dora, AC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!!!!!!!
// Why is there a one in my row of exclamation marks?



Measured memory_bytes: 195584