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: # https://atcoder.jp/contests/agc009/tasks/agc009_a
  # 普通にBの倍数かつAより大きいものの中で最小の数を高速に求めれば良い
  # いや[0,i)を+1増やすらしい。めちゃくちゃめんどくさいやつだ
  
  import sys
  
  sys.setrecursionlimit(1 << 25)
  read = sys.stdin.readline
  ra = range
  enu = enumerate
  
  
  def exit(*argv, **kwarg):
      print(*argv, **kwarg)
      sys.exit()
  
  
  def mina(*argv, sub=1):
      return list(map(lambda x: x - sub, argv))
  
  
  # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
  
  
  def a_int():
      return int(read())
  
  
  def ints():
      return list(map(int, read().split()))
  
  
  def read_col(H):
      """H is number of rows
      A列、B列が与えられるようなとき
      ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合"""
      ret = []
      for _ in range(H):
          ret.append(list(map(int, read().split())))
      return tuple(map(list, zip(*ret)))
  
  
  from math import floor, ceil
  
  N = a_int()
  A, B = read_col(N)
  # 後ろから決定していく
  n_pushed = 0  # すでに何回押されたか(a+n_pushedがその時点での数字の大きさに成る)
  for a, b in zip(reversed(A), reversed(B)):
      a += n_pushed
      x = (ceil(a / b)) * b
      # print(x)
      n_pushed += x - a
  
  print(n_pushed)
  
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"}]