import Control.Monad (replicateM)
import Data.List (partition,delete,(\\))

main = do
    [n,m] <- fmap read . words <$> getLine
    xs <-  fmap (fmap (read :: String -> Int) . words) <$> replicateM m getLine
    print $ length [ () | x <- xs, not $ connected n (delete x xs) ]

connected _ [] = False
connected n (z : zs) = connected' [z] zs [1 .. n]
    where
        connected' _  _ [] = True
        connected' [] _ _  = False
        connected' xs ys ns =
            let f x = any (`elem` x) (concat xs)
                (xs', ys') = partition f ys
            in  connected' xs' ys' (ns \\ concat xs)
