import java.util.*

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T): Comparable<Edge<T>> {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)

    override fun compareTo(other: Edge<T>) = weight.compareTo(other.weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map {it.toInt()}
    val g = Graph(N + 1, 0L, (1e15).toLong()) { a, b -> a + b }

    for (i in 1 .. M) {
        val (A, B) = readLine()!!.split(" ").map { it.toInt() }
        g.edges[A].add(Edge(A, B, 0L))
        g.edges[B].add(Edge(B, A, 0L))
    }

    val vst = Array(N + 1) { false }
    val res = ArrayList<Int>()

    res.add(1)
    vst[1] = true

    fun f() {
        do {
            var updated = false
            for (e in g.edges[res.last()]) {
                if (!vst[e.to]) {
                    vst[e.to] = true
                    res.add(e.to)
                    updated = true
                    break
                }
            }
        } while(updated)
    }

    f()
    res.reverse()
    f()

    println(res.size)
    println(res.joinToString(" "))
}
