Now that the computer industry is stagnant, it is better to go home and raise pigs..so zzk want to be engaged in internet+pig.One day his best friend No.1023 want to know the amount of sows. But big dog No.1023 is very smart.So zzk want to tease him.For example,there is 16 sows,if For example, if there are 16 sows, if 3 pigs are built, the remaining 1 pigs will have no place to settle down. If 5 pigs were built, 1 pigs still had no place to go, and if 7 piggery were built, 2 would have no place to go.You are his fans.You have to give him the exact number of pigs.So what can you do?
Input
the first line contains a integer n (n <= 10) The number of Pigsty,The next N line every lines contains two integers ai, bi( bi ...ai <= 1000), what is meaning that there are ai Pigsties and bi pigs have on place to go.
Output
The smallest number of pig which conforming to conditions.