import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as C
import Data.Graph
import Data.List

main = sol <$> get >>= mapM_ put

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents 

put = putStrLn . show

sol ([n,m]:es) = fmap length $ elems g'
  where
  g = buildG (1,n) $ fmap (\[u,v] -> (u,v)) es
  g' = buildG (bounds g) (edges g ++ reverseE g)

reverseE = edges . transposeG