#AGC009A. Multiple Array

Multiple Array

Score : 300300 points

Problem Statement

There are an integer sequence A1,...,ANA_1,...,A_N consisting of NN terms, and NN buttons. When the ii-th (1iN)(1 \leq i \leq N) button is pressed, the values of the ii terms from the first through the ii-th are all incremented by 11.

There is also another integer sequence B1,...,BNB_1,...,B_N. Takahashi will push the buttons some number of times so that for every ii, AiA_i will be a multiple of BiB_i.

Find the minimum number of times Takahashi will press the buttons.

Constraints

  • All input values are integers.
  • 1N1051 \leq N \leq 10^5
  • 0Ai109(1iN)0 \leq A_i \leq 10^9(1 \leq i \leq N)
  • 1Bi109(1iN)1 \leq B_i \leq 10^9(1 \leq i \leq N)

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

:

ANA_N BNB_N

Output

Print an integer representing the minimum number of times Takahashi will press the buttons.

3
3 5
2 7
9 4
7

Press the first button twice, the second button twice and the third button three times.

7
3 1
4 1
5 9
2 6
5 3
5 8
9 7
22