import Data.List splitEvery2 :: [Int] -> [[Int]] splitEvery2 = takeWhile (not . null) . map (take 2) . iterate (drop 2) main :: IO () main = interact $ show . solve . map (\[x, y] -> y - x) . splitEvery2 . map read . tail . words solve :: [Int] -> Int solve xs = if t /= 1 then -1 else if head xs <= 0 then -1 else head xs where t = length $ group xs