solveEquations :: [[Int]] -> Int solveEquations pairs | all (== ans1) anss && ans1 > 0 = ans1 | otherwise = -1 where anss = map (\(x : y : _) -> y - x) pairs ans1 = head anss main :: IO () main = do _ <- getLine print . solveEquations . map (map read) . map words . lines =<< getContents