import qualified Data.ByteString.Lazy.Char8 as LC import Data.Maybe (fromJust) type Equation a = (a, a) allTheSame :: (Eq a) => [a] -> Bool allTheSame xs = all (== head xs) $ tail xs solve :: Integral a => [Equation a] -> a solve xs | allTheSame anss && ans1 > 0 = ans1 | otherwise = -1 where anss = fmap (\(x, y) -> y - x) xs ans1 = head anss tuplify2 :: [a] -> (a, a) tuplify2 [x, y] = (x, y) tuplify2 _ = error "the length of the list must be two" unsafeReadInt :: LC.ByteString -> Int unsafeReadInt = fst . fromJust . LC.readInt main :: IO () main = getLine >> LC.getContents >>= print . solve . fmap (tuplify2 . fmap unsafeReadInt . LC.words) . LC.lines