let get_input n =
	let rec loop n acc =
		if n = 0 then acc
		else 
			read_line ()
			|> Str.split (Str.regexp " ")
			|> (fun [a; b] -> loop (n - 1) ((int_of_string a, int_of_string b) :: acc))
	in	
	loop n []

(* ceil(m/n) *)
let div_ceil m n =
	float_of_int m /. float_of_int n
	|> ceil
	|> int_of_float

let solve lst =
	let rec loop lst acc =
		match lst with
		| [] -> acc
		| (a, b) :: xs -> 
			loop xs (acc + ((div_ceil (a + acc) b) * b - (a + acc)))
	in
	loop lst 0
	
let () =
	let n = read_int () in
	let lst = get_input n in
	solve lst
	|> print_int
	|> print_newline
