#Q214. 「一本通 6.4 例 4」曹冲养猪

「一本通 6.4 例 4」曹冲养猪

Description

Since Cao Chong successfully dealt with the elephant, Cao Cao began to think about getting his son involved in some business. He sent him to a pig farm in the Central Plains to raise pigs. However, Cao Chong was unhappy and thus worked carelessly. Once, Cao Cao wanted to know the number of sows, so Cao Chong decided to play a trick on him.

For example, suppose there are 1616 sows. If 33 pig pens are built, 11 sow is left without a home; if 55 pig pens are built, there is still 11 sow without a place; if 77 pig pens are built, 22 sows are left without a place. As Cao Cao's personal secretary, it is your duty to report the accurate number of pigs to him. What should you do?

Input Format

The first line contains an integer nn, indicating the number of times pig pens were built.

The next nn lines each contain two integers aia_i and bib_i, indicating that aia_i pig pens were built, and bib_i sows were left without a place. You may assume that aia_i and aja_j are coprime for any ii and jj.

Output Format

Output only a single positive integer, which is the minimum number of sows Cao Chong raised.

Sample 1

3
3 1
5 1
7 2

16

Data Range and Hints

For all data, 1n10,1biai10001\le n\le 10, 1\le b_i\le a_i\le 1000.