main = getLine >> getContents >>= print . solve . map (map read . words) . lines solve :: [[Int]] -> Int solve xs | same xs' && head xs' > 0 = head xs' | otherwise = -1 where xs' = map (\[x, y] -> y - x) xs same (y : ys) = foldl (\acc x -> y == x && acc) True ys