#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) scanf("%d%d", &a[i], &b[i]);
	long long ans = 0;
	for (int i = n; i >= 1; -- i) {
		ans += (ans + a[i] + b[i] - 1) / b[i] * b[i] - (a[i] + ans);
	}
	cout << ans << endl;
}

