f :: [Int]->[[Int]]->Int
f ans []=length ans
f ans ((x:xs):ys)=f [e|e<-xs,e `elem` ans] ys

main = do
       e<-getLine
       es<-getContents
       let (n:m:[])=map read (words e)::[Int]
           xs = map (map read . words) (lines es)::[[Int]]
       putStrLn $ show $ f [1..m] xs