#include using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 }; const long long mod = 998244353; const ll inf = 1LL << 60; const int INF = 1e9 + 1; int main() { ll n; cin >> n; vector> v(3); for (int i = 0; i < 3; i++) cin >> v[i].first >> v[i].second; auto comp = [&](pair& l, pair& r) { if (l.second * r.first == r.second * l.first) l.first < r.first; return l.second * r.first > r.second * l.first; }; sort(v.begin(), v.end(), comp); ll ans = 0; for (int i = 0; i < v[0].first; i++) { for (int j = 0; j < v[0].first; j++) { if (1LL * i * v[1].first + 1LL * j * v[2].first > n) continue; ll ret = (n - 1LL * i * v[1].first - 1LL * j * v[2].first) / v[0].first * v[0].second + i * v[1].second + j * v[2].second; ans = max(ans, ret); } } cout << ans << endl; }