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

import Control.Monad
import Control.Monad.ST
import Data.Char
import Data.List
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.Mutable as SMV
import qualified Data.Sequence as SQ
import Data.Sequence ((|>), (<|), ViewL(..), ViewR(..))

solve :: Int -> SQ.Seq Int -> SMV.IOVector Bool -> MV.IOVector (SQ.Seq Int) -> IO (SQ.Seq Int)
solve a p u v = do
    -- aにリンクしているノード
    lv <- MV.unsafeRead v a
    -- 最初のunusedなノード
    n <- fu u lv
    case n of
        Nothing -> return p
        Just nn  -> do
            SMV.unsafeWrite u nn True
            solve nn (nn<|p) u v

fu u s =
    if SQ.null s
        then return Nothing
        else case s of
            (SQ.viewl -> n:<ns) -> do
                f <- SMV.unsafeRead u n
                if f then fu u ns else return $ Just n

solve2 b p u v = do
    -- bにリンクしているノード
    lv <- MV.unsafeRead v b
    -- 最初のunusedなノード
    n <- fu u lv
    case n of
        Nothing -> return p
        Just nn  -> do
            SMV.unsafeWrite u nn True
            solve2 nn (p|>nn) u v

main = do
    [n,m] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    --
    [a,b] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    --
    v <- MV.replicate (n+1) SQ.empty
    forM_ [1..m-1] $ \_ -> do
        [x,y] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
        MV.unsafeModify v (|>y) x
        MV.unsafeModify v (|>x) y
    --
    uv <- SMV.replicate (n+1) False
    SMV.unsafeWrite uv a True
    SMV.unsafeWrite uv b True
    --
    p <- solve a (SQ.fromList [a,b]) uv v
    (SQ.viewl -> r:<rs) <- solve2 b p uv v
    --
    print $ (+1) $ SQ.length rs
    --
    LB.putStr $ LB.pack $ show r
    --
    forM_ rs $ do \i -> do LB.putStr " "; LB.putStr $ LB.pack $ show i
    LB.putStrLn ""
