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: # -*- coding: utf-8 -*-
  import sys
  import math
  import os
  import itertools
  import string
  import heapq
  import _collections
  from collections import Counter
  from collections import defaultdict
  from functools import lru_cache
  import bisect
  import re
  import queue
  
  
  class Scanner:
      @staticmethod
      def int():
          return int(sys.stdin.readline().rstrip())
  
      @staticmethod
      def string():
          return sys.stdin.readline().rstrip()
  
      @staticmethod
      def map_int():
          return [int(x) for x in Scanner.string().split()]
  
      @staticmethod
      def string_list(n):
          return [input() for i in range(n)]
  
      @staticmethod
      def int_list_list(n):
          return [Scanner.map_int() for i in range(n)]
  
      @staticmethod
      def int_cols_list(n):
          return [int(input()) for i in range(n)]
  
  
  class Math:
      @staticmethod
      def gcd(a, b):
          if b == 0:
              return a
          return Math.gcd(b, a % b)
  
      @staticmethod
      def lcm(a, b):
          return (a * b) // Math.gcd(a, b)
  
      @staticmethod
      def roundUp(a, b):
          return -(-a // b)
  
      @staticmethod
      def toUpperMultiple(a, x):
          return Math.roundUp(a, x) * x
  
      @staticmethod
      def toLowerMultiple(a, x):
          return (a // x) * x
  
      @staticmethod
      def nearPow2(n):
          if n <= 0:
              return 0
          if n & (n - 1) == 0:
              return n
          ret = 1
          while n > 0:
              ret <<= 1
              n >>= 1
          return ret
  
      @staticmethod
      def sign(n):
          if n == 0:
              return 0
          if n < 0:
              return -1
          return 1
  
      @staticmethod
      def isPrime(n):
          if n < 2:
              return False
          if n == 2:
              return True
          if n % 2 == 0:
              return False
          d = int(n**0.5) + 1
          for i in range(3, d + 1, 2):
              if n % i == 0:
                  return False
          return True
  
  
  class PriorityQueue:
      def __init__(self, l=[]):
          self.__q = l
          heapq.heapify(self.__q)
          return
  
      def push(self, n):
          heapq.heappush(self.__q, n)
          return
  
      def pop(self):
          return heapq.heappop(self.__q)
  
  
  MOD = int(1e09) + 7
  INF = int(1e15)
  
  
  def make_divisors(n):
      divisors = []
      for i in range(1, int(n**0.5) + 1):
          if n % i == 0:
              divisors.append(i)
              if i != n // i:
                  divisors.append(n // i)
  
      divisors.sort()
      return divisors
  
  
  def prime_factorize(n):
      a = []
      while n % 2 == 0:
          a.append(2)
          n //= 2
      f = 3
      while f * f <= n:
          if n % f == 0:
              a.append(f)
              n //= f
          else:
              f += 2
      if n != 1:
          a.append(n)
      return a
  
  
  def main():
      # sys.stdin = open("sample.txt")
      N = Scanner.int()
      A, B = [0] * N, [0] * N
      for i in range(N):
          A[i], B[i] = Scanner.map_int()
      ans = 0
      for i in reversed(range(N)):
          A[i] += ans
          if A[i] % B[i] != 0:
              ans += B[i] - A[i] % B[i]
      print(ans)
      return
  
  
  if __name__ == "__main__":
      main()
  
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"}]