#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],b[100005],c[100005];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	memset(c,0,sizeof(c));
	for(int i=n-1;i>=0;i--)
	{
		c[i]+=c[i+1];
		a[i]+=c[i];
		long long add=((((a[i]+b[i]-1)/b[i])*b[i])-a[i]);
		c[i]+=add;
	}
	cout<<c[0]<<endl;
}