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")
  edge[a][b], edge[b][a] = true, true
end

local pos1 = 1
local pos2 = next(edge[1])

local forward = {pos1}
local backward = {pos2}
asked[pos1], asked[pos2] = true, true
local hasdst = true
while hasdst do
  asked[pos1] = true
  hasdst = false
  for dst, _u in pairs(edge[pos1]) do
    if not asked[dst] then
      pos1 = dst
      table.insert(forward, dst)
      hasdst = true
      break
    end
  end
end
hasdst = true
while hasdst do
  asked[pos2] = true
  hasdst = false
  for dst, _u in pairs(edge[pos2]) do
    if not asked[dst] then
      pos2 = dst
      table.insert(backward, dst)
      hasdst = true
      break
    end
  end
end
for i = 1, math.floor(#backward / 2) do
  backward[i], backward[#backward + 1 - i] = backward[#backward + 1 - i], backward[i]
end
for i = 1, #forward do
  table.insert(backward, forward[i])
end
print(#backward)
print(table.concat(backward, " "))
