import Control.Monad
import Control.Applicative

main = do
	[n,m] <- map read.words <$> getLine
	vs <- map (tail.map read.words) <$> replicateM n getLine
	putStrLn.show.length $ foldl f [0..m] vs
f list xs = filter (flip elem list) xs