#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<long long int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	long long int pushed=0;
	for(int i=n-1;i>=0;i--){
		a[i]+=pushed;
		if(a[i]%b[i]!=0){
			pushed+=(b[i]-a[i]%b[i]);
		}
	}
	cout<<pushed<<endl;
	return 0;
}
