#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

LL dp[5000+10];
LL dp2[5000*5000+10];

int main() {
  int n;
  cin >> n;
  vector<int> la, lb;
  for (int i = 0; i < 3; ++i) {
    int a;
    cin >> a;
    la.push_back(a);
  }
  for (int i = 0; i < 3; ++i) {
    int b;
    cin >> b;
    lb.push_back(b);
  }

  for (int i = 0; i <= n; ++i) dp[i] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i+la[j] > n) continue;
      dp[i+la[j]] = max(dp[i+la[j]], dp[i]+lb[j]);
    }
    dp[i+1] = max(dp[i+1], dp[i]+1);
  }

  LL m = dp[n];
  for (int i = 0; i <= m; ++i) dp2[i] = 0;
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i+lb[j] > m) continue;
      dp2[i+lb[j]] = max(dp2[i+lb[j]], dp2[i]+la[j]);
    }
    dp2[i+1] = max(dp2[i+1], dp2[i]+1);
  }

  cout << dp2[m] << endl;
}
