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

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  q <- V.replicateM m $ do
    [x, y] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    return (x-1, y-1)
  let
    ans = V.create $ do
      v <- MV.replicate n (1, False)
      MV.write v 0 (1, True)
      V.forM_ q $ \(x, y) -> do
        red <- snd <$> MV.read v x
        MV.modify v (\(l, b) -> (l+1, if red then red else b)) y
        MV.modify v (\(l, b) -> if l == 1 then (0, False) else (l-1, b)) x
      return v
  print $ V.length $ V.filter snd ans
