#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); ll n, p, q, r, a, b, c; cin >> n >> p >> q >> r >> a >> b >> c; vector M = {p, q, r}; vector R = {a, b, c}; auto P = crt(R, M); pair zero = {0, 0}; if (P == zero) { cout << 0 << endl; return 0; } if (P.first == 0) { cout << n + 1 << endl; return 0; } ll ans = n - P.second; if (ans < 0) { cout << 0 << endl; return 0; } cout << ans / P.first + 1 << endl; }