import Data.List
main = interact$show.solve.sort.map read.tail.words

solve :: [Int] -> Int
solve x = length (tower x)
tower :: [Int] -> [Int]
tower (a:[]) = [a]
tower (a:b:[]) = if a==b then [b] else [a,b]
tower (a:b:x) = if a==b then tower (b:x) else [a] ++ tower (b:x)