import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict as M
import Data.List

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

readIntPair :: B.ByteString -> [(Int, Int)]
readIntPair = map (pair . map readInt . B.words) . B.lines

pair :: [t] -> (t, t)
pair [x, y] = (x, y)
pair _ = undefined

main = do
  [n,m] <- map read . words <$> getLine
  xys <- readIntPair <$> B.getContents
  print (boxball n m xys)

boxball n m = length . filter id . map snd . M.elems . foldl' sim im0
  where
    im0 = M.fromDistinctAscList $ (1,(1::Int,True)) : [(i,(1,False)) | i <- [2..n]]

sim im (x,y)
  | v1==1 && f1 = M.insert x (0, False) (M.insert y (v2+1, True) im)
  | f1 = M.insert x (v1-1, f1) (M.insert y (v2+1, True) im)
  | v1==1 = M.insert x (0, False) (M.insert y (v2+1, f2) im)
  | otherwise = M.insert x (v1-1, f1) (M.insert y (v2+1, f2) im)
  where
    (v1,f1) = im M.! x
    (v2,f2) = im M.! y