{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.ST
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as M

main :: IO ()
main = readLine >>= main'
    where
        main' [n, m] = readContents m >>= print . solve n m

solve :: Int -> Int -> [[Int]] -> Int
solve n m xys = V.length . V.filter snd $ V.create (initialize >>= calc (map (map pred) xys))
    where
        initialize :: ST s (M.STVector s (Int, Bool))
        initialize = M.replicate n (1, False) >>= edit
            where
                edit vs = vs <$ M.unsafeWrite vs 0 (1, True)

        calc ([x, y] : zs) vs = oldValues >>= check >> calc zs vs
            where
                oldValues = (,) <$> M.unsafeRead vs x <*> M.unsafeRead vs y
                check ((pxn, pxb), (pyn, pyb)) = M.unsafeWrite vs x (pxn - 1, xb) >> M.unsafeWrite vs y (pyn + 1, yb)
                    where
                        xb 
                            | pxn > 1 = pxb
                            | otherwise = False
                        yb = pxb || pyb
        calc _ vs = return vs

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine