import qualified Data.Vector.Unboxed as V
import qualified Data.Sequence as SQ
import qualified Data.Map as MP
import Data.Tuple
import Data.Maybe
import Data.List

type Graph = MP.Map Int (V.Vector Int)

toTuple :: [Int] -> (Int, Int)
toTuple [a, b] = (a, b)

make :: Int -> Int -> V.Vector (Int, Int) -> Graph
make n m es = graph
    where
        init = V.foldl' (\g from -> MP.insert from (V.empty) g) MP.empty (V.fromList [1..n])
        graph = V.foldl' (\g (from, to) -> MP.adjust (V.cons to) from g) init (es V.++ V.map swap es)

solve :: Graph -> SQ.Seq Int -> [Int] -> Int -> [()] -> [()]
solve graph queue arrived prev acc = case SQ.viewl queue of
                (v SQ.:< queue') ->
                    if v `notElem` arrived
                        then solve graph queue' arrived prev acc
                        else 
                            let 
                                vs = fromJust $ MP.lookup v graph 
                                queue'' = V.foldl' (\q nv -> (SQ.<|) nv q) queue' (V.filter (/=prev) vs)
                                d = delete v arrived
                            in
                                if null d 
                                    then solve graph queue'' arrived v (():acc)
                                    else solve graph queue'' d v acc
                SQ.EmptyL ->
                    acc

main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    es <- V.replicateM m (toTuple . map read . words <$> getLine)
    let graph = make n m es 
    let res =  solve graph (SQ.singleton 1) [1..n] (-1) []
    print $ length res