import Data.List

solve :: [Int] -> Int
solve (a:b:xs)
  | b /= 0 = solve $ reverse $ sort $ (a-b):0:xs
  | otherwise = a

main = getContents >>= print . (\x -> (length . nub) x - (solve . reverse . sort . map ((subtract 1) . length) . group . sort) x) . map (read :: String -> Int) . words . last . lines