local n, m = io.read("*n", "*n")
local edge = {}
local asked = {}
for i = 1, n do
  edge[i] = {}
  asked[i] = false
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end

local src = 1
asked[1] = true
local forward = {}
while true do
  local found = false
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if not asked[dst] then
      asked[dst] = true
      table.insert(forward, dst)
      src = dst
      found = true
      break
    end
  end
  if not found then break end
end
local backward = {}
src = 1
while true do
  local found = false
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if not asked[dst] then
      asked[dst] = true
      table.insert(backward, dst)
      src = dst
      found = true
      break
    end
  end
  if not found then break end
end
local ret = {}
for i = #backward, 1, -1 do
  table.insert(ret, backward[i])
end
table.insert(ret, 1)
for i = 1, #forward do
  table.insert(ret, forward[i])
end
print(#ret)
print(table.concat(ret, " "))
