void main()
{
    long n = readln.chomp.to!long;

    long[] a = new long[n], b = new long[n];
    foreach (i; 0 .. n)
    {
        long[] tmp = readln.split.to!(long[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }

    long buttons;
    foreach_reverse (i; 0 .. n)
    {
        long r = (a[i] + buttons) % b[i];
        if (r)
        {
            buttons += b[i] - r;
        }
    }

    buttons.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;