import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


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

  auto a = new long[](n);
  auto b = new long[](n);

  long res;
  foreach (i; 0..n) {
    auto x = readln.chomp.split.to!(long[]);
    a[i] = x[0];
    b[i] = x[1];
  }
  foreach_reverse(i; 0..n) {
    auto s = (a[i] + res) % b[i];
    if (s == 0) continue;
    res += b[i] - s;
  }
  res.writeln;
}
