import Control.Monad
import qualified Data.Vector.Unboxed as UV

main=do
    [n,m]<-map read.words<$>getLine::IO[Int]
    as<-replicateM n $ tail.map read.words<$>getLine::IO[[Int]]
    print $ f n m as

f::Int->Int->[[Int]]->Int
f n m as = UV.length $ UV.filter (==n) $ sv m as
    where
        sv m = foldl ac (UV.replicate m 0)
        ac sv a0 = UV.accum (+) sv $ map (\a->(a-1,1)) a0
