import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Control.Monad

main :: IO ()
main = do
  [n, _] <- map read . words <$> getLine
  q <- map (map (fst . fromJust . BS.readInt) . BS.words) . BS.lines <$> BS.getContents
  let
    ans = V.create $ do
      vn <- MV.replicate n (1 :: Int)
      vb <- MV.replicate n False
      MV.write vb 0 True
      forM_ q $ \[x, y] -> do
        red <- MV.read vb x
        MV.modify vn (+1) y
        MV.modify vb (\b -> red || b) y
        MV.modify vn (subtract 1) x
        l <- MV.read vn x
        MV.modify vb (\b -> (l /= 0) && b) x
      return vb
  print $ V.length $ V.filter id ans
