#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } #include using namespace atcoder; int main() { fast_io(); long long n; cin >> n; long long p, q, r; cin >> p >> q >> r; long long a, b, c; cin >> a >> b >> c; auto [y, z] = crt({a, b, c}, {p, q, r}); cout << n / z + (n % z >= y ? 1 : 0) << endl; }