operations :: [String] -> Int operations (s : t : _) = operations' 0 [s, t] where operations' n [[], []] = n operations' n [(s : ss), (t : ts)] | s == t = operations' n [ss, ts] | otherwise = flip operations' [ss, ts] $ n + 1 main :: IO () main = getLine >> getContents >>= print . operations . lines