import sys import math input = sys.stdin.readline k = int(input()) N = [tuple(map(int, input().split())) for _ in range(k)] lgN = sum(math.log(p) * e for p, e in N) P = N[-1][0] lg = 0.0 err = math.inf R = -1 for i in range(P): lg += math.log(P - i) - math.log(i + 1) if err > abs(lg - lgN): err = abs(lg - lgN) R = i + 1 for p, e in N: def f(x): ans = 0 while True: x //= p if x == 0: return ans ans += x if e != f(P) - f(P - R) - f(R): exit(print(-1, -1)) print(P, R)