#include #include using namespace std; typedef long long ll; int main() { ll n; cin >> n; vector p(3), r(3); for (int i = 0; i < 3; i++) { cin >> p[i]; } for (int i = 0; i < 3; i++) { cin >> r[i]; } auto [tr, tm] = atcoder::crt(r, p); ll ans = n / tm; if (n % tm >= tr) ans++; cout << ans << endl; return 0; }