let solve n st = let rec solve' i result = if i >= n then result else ( let x, y = Stream.next st in if (result = -1 && y - x > 0) || (result <> -1 && result = y - x) then solve' (i + 1) (y - x) else -1 ) in solve' 0 (-1) let () = let n = read_line () |> int_of_string in let st = Stream.from(fun i -> if i >= n then None else let x, y = read_line () |> fun l -> Scanf.sscanf l "%d %d" (fun x y -> (x, y)) in Some(x, y)) in solve n st |> string_of_int |> print_endline