#include using i64 = long long; std::vector minp, primes; void sieve(int n) { minp.assign(n + 1, 0); primes.clear(); for (int i = 2; i <= n; i++) { if (minp[i] == 0) { minp[i] = i; primes.push_back(i); } for (auto p : primes) { if (i * p > n) { break; } minp[i * p] = p; if (p == minp[i]) { break; } } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int k; std::cin >> k; std::vector p(k), e(k); for (int i = 0; i < k; i++) { std::cin >> p[i] >> e[i]; } int P = p[k - 1]; sieve(P); std::vector pw(P + 1); int cnt = 0; for (int i = 0; i < k; i++) { pw[p[i]] = e[i]; } for (int i = 1; i <= P; i++) { cnt += (pw[i] != 0); } int r = 0; while (cnt != 0 && r < P) { r++; for (int x = P - r + 1; x > 1; x /= minp[x]) { int p = minp[x]; cnt -= (pw[p] != 0); pw[p]--; cnt += (pw[p] != 0); } for (int x = r; x > 1; x /= minp[x]) { int p = minp[x]; cnt -= (pw[p] != 0); pw[p]++; cnt += (pw[p] != 0); } } if (cnt != 0) { std::cout << -1 << " " << -1 << "\n"; return 0; } std::cout << P << " " << r << "\n"; return 0; }