output_description: Print an integer representing the minimum number of times Takahashi will press
  the buttons.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N
      A_1 B_1
      :
      A_N B_N
attempt: import sys, collections as cl, bisect as bs
  
  sys.setrecursionlimit(100000)
  input = sys.stdin.readline
  mod = 10**9 + 7
  Max = sys.maxsize
  
  
  def l():  # intのlist
      return list(map(int, input().split()))
  
  
  def m():  # 複数文字
      return map(int, input().split())
  
  
  def onem():  # Nとかの取得
      return int(input())
  
  
  def s(x):  # 圧縮
      a = []
      if len(x) == 0:
          return []
      aa = x[0]
      su = 1
      for i in range(len(x) - 1):
          if aa != x[i + 1]:
              a.append([aa, su])
              aa = x[i + 1]
              su = 1
          else:
              su += 1
      a.append([aa, su])
      return a
  
  
  def jo(x):  # listをスペースごとに分ける
      return " ".join(map(str, x))
  
  
  def max2(x):  # 他のときもどうように作成可能
      return max(map(max, x))
  
  
  def In(x, a):  # aがリスト(sorted)
      k = bs.bisect_left(a, x)
      if k != len(a) and a[k] == x:
          return True
      else:
          return False
  
  
  def pow_k(x, n):
      ans = 1
      while n:
          if n % 2:
              ans *= x
          x *= x
          n >>= 1
      return ans
  
  
  """
  def nibu(x,n,r):
      ll = 0
      rr = r
      while True:
          mid = (ll+rr)//2
  
      if rr == mid:
          return ll
      if (ここに評価入れる):
          rr = mid
      else:
          ll = mid+1
  """
  
  n = onem()
  po = []
  for i in range(n):
      po.append(l())
  
  co = 0
  
  for i in range(n):
      on = po[-(i + 1)]
      on[0] += co
      co += ((on[1] - on[0]) % on[1]) if on[1] % on[0] != 0 else 0
  
  print(co)
  
problem_description: Statement
  
  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.
samples: [{"input": "3\n    3 5\n    2 7\n    9 4", "output": "7\n    \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n    3 1\n    4 1\n    5 9\n    2 6\n    5 3\n    5 8\n    9 7", "output": "22"}]