p03821 AtCoder Grand Contest 009 - Multiple Array
There are an integer sequence A_1,...,A_N consisting of N terms, and N buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.

There is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.

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

Constraints

* All input values are integers.
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)
* 1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)

Input

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


N
A_1 B_1
:
A_N B_N


Output

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

Examples

Input

3
3 5
2 7
9 4


Output

7


Input

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


Output

22
```python
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]

s = 0
for A, B in AB[::-1] :
  x = (A + s + B - 1) // B
  s += x * B - (A + s)
  
print(s)
```