#include #include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector m(3), r(3); for(auto &&v : m) cin >> v; for(auto &&v : r) cin >> v; auto [rem, mod] = atcoder::crt(r, m); if(mod == 0){ cout << "0\n"; return 0; } cout << max(0ll, n + mod - rem) / mod << '\n'; }