import java.io.*;
import java.util.*;

public class where_pk {
	public static void main(String[] args) {
		new where_pk().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		assert((1 <= n) && (n <= 1000));
		assert((1 <= m) && (m <= 200000));
		assert((1 <= k) && (k <= 1e9));
		ArrayList<Integer>[] a = new ArrayList[n];
		for (int i = 0; i < n; i++)
			a[i] = new ArrayList<Integer>();
		boolean[][] was = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			a[x].add(y);
			a[y].add(x);
			assert((0 <= x) && (x < n));
			assert((0 <= y) && (y < n));
			assert(!was[x][y]);
			was[x][y] = true;
		}
		assert(a[0].size() > 0);
		int[][] r = new int[n][2];
		for (int i = 0; i < n; i++) {
			r[i][0] = k + 1;
			r[i][1] = k + 1;
		}
		r[0][0] = 0;
		ArrayList<Integer> q = new ArrayList<Integer>();
		q.add(0);
		int z = 0;
		while (z < q.size()) {
			int tV = q.get(z) / 2;
			int d = r[tV][q.get(z) % 2];
			for (int i = 0; i < a[tV].size(); i++) {
				if (d + 1 < r[a[tV].get(i)][(d + 1) % 2]) {
					r[a[tV].get(i)][(d + 1) % 2] = d + 1;
					q.add(a[tV].get(i) * 2 + (d + 1) % 2);
				}
			}
			z++;
		}
		ArrayList<Integer> ans = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (r[i][k % 2] <= k)
				ans.add(i + 1);
		}
		out.println(ans.size());
		for (int i = 0; i < ans.size(); i++) {
			out.print(ans.get(i));
			if (i < ans.size() - 1)
				out.print(" ");
		}
		out.println();
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			br = new BufferedReader(new FileReader("where.in"));
			out = new PrintWriter("where.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}