{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Data.Char
import Data.List
import Data.Maybe
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as LB
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Storable as SV
import qualified Data.Vector.Storable.Mutable as SMV

solve pa@(lh:p) ed ud =
    case find (ud SV.!) nl of
        Just n -> solve (n:pa) ed (use n ud)
        Nothing -> solve2 (reverse pa) ed ud
    where
        nl = ed V.! lh

solve2 pa@(lh:p) ed ud =
    case find (ud SV.!) nl of
        Just n -> solve2 (n:pa) ed (use n ud)
        Nothing -> pa
    where
        nl = ed V.! lh

adde :: V.Vector [Int] -> [Int] -> IO (V.Vector [Int])
adde v [a,b] = return $ runST $ do
    v' <- V.unsafeThaw v
    av <- MV.unsafeRead v' a
    MV.unsafeWrite v' a (b:av)
    bv <- MV.unsafeRead v' b
    MV.unsafeWrite v' b (a:bv)
    V.freeze v'

use n v = runST $ do
    v' <- SV.unsafeThaw v
    SMV.unsafeWrite v' n False
    SV.unsafeFreeze v'

main = do
    [n,m] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    --
    [a,b] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    ev <- replicateM (m-1) $ unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    v <- foldM adde (V.replicate (n+1) []) ev
    --
    let uv = use b $ use a (SV.replicate (n+1) True)
    --
    let ra@(r:rs) =  solve [a,b] v uv
    --
    print $ length ra
    LB.putStr $ LB.pack $ show r
    forM_ rs $ do \i -> do LB.putStr " "; LB.putStr $ LB.pack $ show i
    LB.putStrLn ""
