{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
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 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

solve :: Int -> Int -> [(Int, Int)] -> Maybe [Int]
solve n m abList = if (IM.size ansMap) == n
    then Just $ tail $ IM.elems ansMap
    else Nothing
  where
  graph = IM.fromListWith (<>) $ [p | (a, b) <- abList, p <- [(a, [b]), (b, [a])]]
  ansMap = go [1] (IM.fromList [(1, 1)]) $ (n - 1)
  go :: [Int] -> IM.IntMap Int -> Int -> IM.IntMap Int
  go [] ansList _ = ansList
  go rooms ansList 0 = ansList
  go rooms ansList remaining = go nextRooms nextMap $ remaining - IM.size nextAns where
    nextAns = IM.fromList [(nextRoom, room)|room <- rooms, nextRoom <-graph IM.! room, IM.notMember nextRoom ansList]
    nextMap = IM.union ansList nextAns
    nextRooms = IM.keys nextAns

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


Measured memory_bytes: 118308