Let us choose k different positive integers a1, a2, …, ak. For some non-negative integer x, divide it by ai(1 <= i <= k), we can get k remainders r1, r2,…, rk. Now give you ai and ri, please find the minimum x. If such x does not exist, print -1.
The first line will be the integer k.
k lines, each line will contain two integers ai, ri.