let () = let n = Scanf.scanf "%d " (fun i -> i) in let rec doit i z = if i = n then z else let x, y = Scanf.scanf "%d %d " (fun x y -> x, y) in if x > y then (-1) else let s = y - x in if z <> (-1) && z <> s then (-1) else doit (i + 1) s in doit 0 (-1) |> Printf.printf "%d\n"