import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a, int[] b) {
    int sum = 0;
    for (int i = cast(int)a.length - 1; i >= 0; i--) {
        int x = sum + a[i];

        if (x > b[i]) {
            int m = x % b[i];
            if (m > 0) {
                sum += b[i] - m;
            }
        }
        else {
            sum += b[i] - x;
        }
    }
    return sum;
}

void main() {
    int n = readint;
    int[] a, b;
    for (int i = 0; i < n; i++) {
        auto ab = readints;
        a ~= ab[0];
        b ~= ab[1];
    }
    writeln(calc(a, b));
}
