Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim A(N - 1), B(N - 1), ans As Long

        For i As Integer = 0 To N - 1
            A(i) = NextInt()
            B(i) = NextInt()
        Next

        For i As Integer = N - 1 To 0 Step -1
            A(i) += ans
            If A(i) Mod B(i) <> 0 Then
                ans += Math.Abs(A(i) Mod B(i) - B(i))
            End If
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module
