{-# 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.Sequence as S
import qualified Data.Set as Set
import Data.Sequence ((|>), (<|), ViewL(..), ViewR(..))

vl (n:<_) = n
vr (_:>n) = n

f a [x,y] = a==x || a==y
g a b xy = f a xy || f b xy

pick _ _ _ _ [] _ = Nothing
pick path ps a b ((xy@[x,y]):vs) rv
    | a == x && Set.notMember y ps = Just ((y,a),vs ++ rv)
    | a == y && Set.notMember x ps = Just ((x,a),vs ++ rv)
    | b == x && Set.notMember y ps = Just ((y,b),vs ++ rv)
    | b == y && Set.notMember x ps = Just ((x,b),vs ++ rv)
    | g a b xy = pick path ps a b vs rv
    | True = pick path ps a b vs (xy:rv)

solve :: S.Seq Int -> Set.Set Int -> [[Int]] -> S.Seq Int
solve path ps vs =
    case pick path ps lh rh vs [] of
        Nothing -> path
        Just ((a,b), v) | lh==b -> solve (a<|path) (Set.insert a ps) v
        Just ((a,b), v) | rh==b -> solve (path|>a) (Set.insert a ps) v
    where
        lh = vl $ S.viewl path
        rh = vr $ S.viewr path

main = do
    [n,m] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    [a,b] <- unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    v <- replicateM (m-1) $ unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
    let (S.viewl -> r:<rs) =  solve (S.fromList [a,b]) (Set.fromList [a,b]) v
    print $ (+1) $ S.length rs
    LB.putStr $ LB.pack $ show r
    forM_ rs $ do \i -> do LB.putStr " "; LB.putStr $ LB.pack $ show i
    LB.putStrLn ""
