import Data.List import Control.Applicative import Control.Monad main = do n <- readLn c <- (map . map) (read :: String -> Int) . map words <$> replicateM n getLine let c' = map (\x -> x !! 1 - x !! 0) c s = (head c) !! 1 - (head c) !! 0 print $ if and $ map (== s) c' then if s < 0 then -1 else s else -1