import Control.Monad.State
--import Control.Monad
import qualified Data.Map as M
--import Data.Maybe

type Edge = M.Map (Int, Int) Bool
type Path = [Int]
type EState = State (Edge, Path, Int) Int

main :: IO ()
main = do
  [n, m] <- getInts
  nss <- replicateM m $ do
    [a, b] <- getInts
    return (a, b)
  let edge = toEdge nss M.empty
  --mapM_ print $ M.toList edge
  let (first, next) = head nss
  let (_, ans, _) = execState solve (edge, [first], n)
  print $ length ans
  putStrLn $  toStr ans 

toStr :: [Int] -> String
toStr = foldr (\a b -> show a ++ " " ++ b) [] 
  
getInts :: IO [Int]
getInts = map read . words <$> getLine

toEdge :: [(Int, Int)] -> Edge -> Edge
toEdge [] e = e
toEdge ((a, b):ns) e = toEdge ns (M.insert (a,b) True (M.insert (b, a) True e))

solve :: EState
solve = do
  (edge, path, n) <- get
  let from = head path
  let candidate = lookupMemo from edge n
  let edge' = foldl (\b a -> M.delete (a, from) (M.delete (from, a) b)) edge [1..n]
  case candidate of
    Just a -> do
      put (edge', a:path, n)
      solve
    Nothing -> return 0
  where
    lookupMemo :: Int -> Edge -> Int -> Maybe Int
    lookupMemo from edge n = go $  zip [1..n] $ repeat from 
          where
            go [] = Nothing
            go ((a, b):ns) = case M.lookup (a, b) edge of
                               Just True -> Just a
                               _ -> go ns 
