import Control.Applicative

getArr :: IO [Int]
getArr = map read . words <$> getLine

getKA :: Int -> [[Int]] -> IO [[Int]]
getKA 0 out = return out
getKA c out = do
  x <- (: out) <$> tail <$> getArr
  getKA (c-1) x

solve :: Int -> [[Int]] -> [Int] -> [Int]
solve 1 _ out      = out
solve c (x:xs) out = solve (c-1) xs (check x out)
  where
    check :: [Int] -> [Int] -> [Int]
    check a b = filter (/=0) $ map (\x->if elem x a then x else 0) b

main :: IO ()
main = do
  [n,_] <- getArr
  x <- getKA n []
  putStrLn $ show $ length $ solve n (tail x) (head x)