#include <bits/stdc++.h>

#define int long long
template <typename T> void maxi(T& a, T b) {a = std::max(a, b);}

int32_t main() {
  int n;
  scanf("%lld", &n);

  std::vector<int> a(4, 1);
  for (int i = 0; i < 3; i++)
    scanf("%lld", &a[i]);

  std::vector<int> b(4, 1);
  for (int i = 0; i < 3; i++)
    scanf("%lld", &b[i]);

  std::vector<int> dp(n+1);
  //dp[i] -> maximum value with capacity i

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      const int wt = a[j], v = b[j];
      if (wt <= i)
        maxi(dp[i], dp[i - wt] + v);
    }
  }

  n = dp[n];
  dp.clear();
  dp.resize(n+1);

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      const int wt = b[j], v = a[j];
      if (wt <= i)
        maxi(dp[i], dp[i - wt] + v);
    }
  }

  printf("%lld", dp[n]);
  return 0;
}
