import qualified Data.ByteString.Char8 as BS
import qualified Data.List as L
import qualified Data.Set as S
import qualified Control.Monad as M
import Data.Maybe (fromJust)
import Data.Ord
import qualified Data.Vector.Unboxed as V

main = do
 [n,k] <- map read <$> words <$> getLine
 h <- V.fromList <$>(1:)<$>map (fst.fromJust.BS.readInt) <$> BS.words<$>BS.getLine
 ab <- L.groupBy (\(x:_) (y:_) -> x == y) <$>L.sortBy (comparing head)<$>concat <$>M.replicateM k gen
 let result = map (tester h) ab
 print ( (length$filter (null) result) + (n- (length result))  )

gen = do
 k<-map (fst.fromJust.BS.readInt) <$>BS.words<$>BS.getLine
 return [k,reverse k]

tester hlist list = filter (m<=) $map (hlist V.!) checker
 where
  checker = map last list
  m = hlist V.! (head $head list)
