{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

modN = 1000000007

pow :: Num a => a -> Int -> a
pow base 0 = 1
pow base 1 = base
pow base time
    | odd time = let
        a = pow base (div time 2)
        in
        a * a * base
    | otherwise = let
        a = pow base (div time 2)
        in
        a * a

inv :: ModNum -> ModNum
inv a = pow a $ modN - 2

newtype ModNum = ModNum {getInt :: Int} deriving (Show, Eq, Ord)
instance Num ModNum where
    (+) (ModNum a) (ModNum b) = ModNum $ mod (a + b) modN
    (-) (ModNum a) (ModNum b)
            | a < b = (ModNum $ a + modN) - ModNum b
            | otherwise = ModNum $ mod (a - b) modN
    (*) (ModNum a) (ModNum b) = ModNum $ mod (a * b) modN
    abs (ModNum a)
            | a < 0 = abs . ModNum $ a + modN
            | otherwise = ModNum a
    signum (ModNum a) = ModNum $ signum a
    fromInteger i = abs . ModNum . fromIntegral $ mod i (fromIntegral modN)

mDiv :: ModNum -> ModNum -> ModNum
mDiv a b = a * inv b

newtype MyGraph = MyGraph (V.Vector [Int])

listToGraph :: Int -> [(Int, Int)] -> Bool -> MyGraph
listToGraph n paths inverse = MyGraph $ runST $ do
    a <- MV.replicate n []
    forM_ paths $ \(from, to) -> do
        MV.modify a (to:) $ from - 1
        when inverse $ MV.modify a (from:) $ to - 1
    GV.freeze a

vecToGraph :: Int -> V.Vector (Int, Int) -> Bool -> MyGraph
vecToGraph n paths inverse = MyGraph $ runST $ do
    a <- MV.replicate n []
    GV.forM_ paths $ \(from, to) -> do
        MV.modify a (to:) $ from - 1
        when inverse $ MV.modify a (from:) $ to - 1
    GV.freeze a

getPaths :: Int -> MyGraph -> [Int]
getPaths i (MyGraph lst) = lst GV.! (i - 1)

solve :: Int -> Int -> V.Vector (Int, Int) -> Maybe [Int]
solve n m abVec = Just . tail . GV.toList $ runST $ do
    ansVec <- MV.replicate n (negate 1)
    go (Seq.singleton (1, 1)) ansVec n
    GV.freeze ansVec
  where
  graph = vecToGraph n abVec True
  getNext = flip getPaths graph
  go :: Seq.Seq (Int, Int) -> MV.MVector s Int -> Int -> ST s ()
  go rooms ansVec 0 = pure ()
  go Seq.Empty ansVec 0 = pure ()
  go ((room, from) Seq.:<| rooms) ansVec remaining = do
    val <- MV.read ansVec $ (ts room) - 1
    if val == -1 then do
      MV.write ansVec (room - 1) from
      let next = Seq.fromList $ (,room) <$> getNext room
      go (rooms Seq.>< next) ansVec $ remaining - 1
    else
      go rooms ansVec remaining


main :: IO ()
main = do
  (n, m) <- readTuple2
  abVector <- GV.replicateM m readTuple2
  case solve n m abVector of
    Nothing -> putStrLn "No"
    Just xs -> do
      putStrLn "Yes"
      forM_ xs print


Measured memory_bytes: 107772