#include <iostream>
#include <vector>

typedef long long TI;
typedef std::vector<TI> VI;
typedef std::vector<VI> VVI;

TI ks(TI n, VI as, VI bs) {
  auto dp = VVI(as.size()+1);
  dp[0] = VI(n+1, 0);
  for(int i=1; i<=3; ++i) {
    //std::cerr << "--------" << std::endl;
    dp[i] = VI(n+1, 0);
    auto a = as[i-1];
    auto b = bs[i-1];
    for(TI m=1; m<=n; ++m) {
      //std::cerr << dp[i-1][m];
      dp[i][m] = dp[i-1][m] > dp[i][m] ? dp[i-1][m] : dp[i][m];
      if (m - a >= 0) {
        auto v = dp[i][m - a] + b;
        //std::cerr << " " << v;
        dp[i][m] = v > dp[i][m] ? v : dp[i][m];
      }
      //std::cerr << " " << dp[i][m] << std::endl;
    }
  }
  TI ans = 0;
  for(TI m=0; m<=n; ++m) {
    auto v = n-m+dp[3][m];
    ans = v > ans ? v : ans;
  }
  return ans;
}

int main() {
  TI N;
  auto gsb0 = VI(3);
  auto gsb1 = VI(3);
  std::cin >> N;
  for(int i=0; i<3; ++i) std::cin >> gsb0[i];
  for(int i=0; i<3; ++i) std::cin >> gsb1[i];

  auto M = ks(N, gsb0, gsb1);
  std::cerr << "*" << M << "*" << std::endl;
  auto V = ks(M, gsb1, gsb0);
  std::cout << V << std::endl;
}
