local n=io.read("*n")
local a,b={},{}
for i=1,n do
    a[i],b[i]=io.read("*n","*n")
end

local push=0
for i=n,1,-1 do
    a[i]=a[i]+push
    if a[i]%b[i]~=0 then
        push=push+b[i]-a[i]%b[i]
    end
end
print(push)