import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n = readln.chomp.to!int;
	BigInt[] as, bs;
	for(int i = 0; i < n; i ++){
		ulong[] tmp = readln.chomp.split.map!(to!ulong).array;
		as ~= BigInt(tmp[0]), bs ~= BigInt(tmp[1]);
		}
	BigInt ans = 0;
	for(int i = n - 1; i >= 0; i --){
		BigInt x = ans;
		x += as[i];
		x = x % bs[i];
		if(x > 0) ans += bs[i] - x;
		}
	
	ans.writeln;
	}