minMoves :: [Int] -> Int minMoves (x : y : x2 : y2 : _) | x == y && x2 < x && x2 == y2 = 1 + m | otherwise = m where m = max x y main :: IO () main = print . minMoves . map read . words =<< getContents