import Control.Monad import Data.List rInteger :: String -> Integer rInteger = read a4b [x,y] = x + y * 4 main = do n <- readLn ls <- sort . map a4b . map (map rInteger . words) <$> replicateM n getLine let ls' = map ((last ls) -) ls result | any (odd) ls' = -1 | otherwise = (sum ls') `div` 2 --print ls --print ls' print result