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

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  q <- replicateM m (listToPair . map (subtract 1) <$> readIntLns)
  let
    ans = V.create $ do
      v <- MV.replicate n (1, False)
      MV.write v 0 (1, True)
      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

readLns :: (Read a) => IO [a]
readLns = map read . words <$> getLine
readPair :: (Read a) => IO (a, a)
readPair = listToPair <$> readLns
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt
readIntLns :: IO [Int]
readIntLns = map readInt . BS.words <$> BS.getLine
readIntLn :: IO Int
readIntLn = readInt <$> BS.getLine
readIntPair :: IO (Int, Int)
readIntPair = listToPair <$> readIntLns

listToPair :: [a] -> (a, a)
listToPair (a:b:_) = (a, b)
