main = getContents >>= print . wafu . map (map read . words) . tail . lines wafu nss = if n>0 && all (==n) ns then n else -1 where (n:ns) = map (\[x,y] -> y-x) nss