import Control.Monad main = do n <- readLn xys <- replicateM n $ liftM (map read . words) getLine let zs@(z:_) = map (\[x, y] -> y - x) xys in print $ if all (==z) zs && z > 0 then z else (-1)