Problem1276--zzk's trouble(1)

1276: zzk's trouble(1)

[Creator : ]
Time Limit : 1 sec  Memory Limit : 128 MB

Description

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.

Sample Input Copy

3
3 1
5 1
7 2

Sample Output Copy

16

Source/Category