#include using namespace std; #include using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; using ll = long long; using ld = long double; using pll = pair; using tlll = tuple; constexpr ll INF = 1LL << 60; template bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {return (A % M + M) % M;} ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);} template void unique(vector &V) {V.erase(unique(V.begin(), V.end()), V.end());} template void sortunique(vector &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) ll modinv(ll a, ll m) { ll b = m, x = 1, y = 0; while (b > 0) { ll q = a / b, r = a - q * b, s = x - q * y; a = b, b = r; x = y, y = s; } return (x % m + m) % m; } ll precrt(vector &R, vector &M, ll md) { ll N = R.size(); for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { ll g = gcd(M.at(i), M.at(j)); if (R.at(i) % g != R.at(j) % g) return -1; M.at(i) /= g, M.at(j) /= g; ll gi = gcd(M.at(i), g), gj = g / gi; do { g = gcd(gi, gj); gi *= g, gj /= g; } while (g > 1); M.at(i) *= gi, M.at(j) *= gj; R.at(i) %= M.at(i), R.at(j) %= M.at(j); } } ll res = 1; for (ll i = 0; i < N; i++) { res *= M.at(i), res %= md; } return res; } ll modcrt(vector &R, vector &M, ll md) { ll N = R.size(); assert(M.size() == N); vector X(N), L(N); ll l = M.at(0), x = R.at(0) % l; for (ll i = 1; i < N; i++) { X.at(i) = x % M.at(i); L.at(i) = l % M.at(i); } x %= md, l %= md; for (ll i = 1; i < N; i++) { ll xi = X.at(i), li = L.at(i); ll mi = M.at(i), ri = R.at(i) % mi; ll t = safemod((ri - xi) * modinv(li, mi), mi); for (ll j = i + 1; j < N; j++) { X.at(j) += t * L.at(j) % M.at(j); L.at(j) *= mi, L.at(j) %= M.at(j); } x += t * l % md; l *= mi, l %= md; } return x; } int main() { ll N; cin >> N; vector X(N), Y(N); for (ll i = 0; i < N; i++) { cin >> X.at(i) >> Y.at(i); } const ll MOD = 1000000007; ll lcm = precrt(X, Y, MOD); if (lcm == -1) FINALANS(-1); if (X == vector(N, 0)) FINALANS(lcm); ll ans = modcrt(X, Y, MOD); cout << ans << endl; }