#include <iostream>
using namespace std;

int main() {
	long long int N, count = 0, a[100000], b[100000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = N - 1; i >= 0; i--) {
		count += b[i] - (a[i] + count + b[i] - 1) % b[i] - 1;
	}
	cout << count << endl;
}