import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; public class Main { static int n, n2; static List> list; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); n = Integer.parseInt(sa[2]); n2 = n * 2; list = new ArrayList<>(n2); for (int i = 0; i < n2; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { sa = br.readLine().split(" "); Hen h = new Hen(); h.i = i; h.x = Integer.parseInt(sa[0]) - 1; h.y = Integer.parseInt(sa[1]) - 1 + n; list.get(h.x).add(h); list.get(h.y).add(h); } br.close(); for (int i = 0; i < n2; i++) { if (dfs(i, null, new LinkedHashSet<>())) { return; } } System.out.println(-1); } static boolean dfs(int x, Hen p, LinkedHashSet his) { for (Hen h : list.get(x)) { if (h != p) { if (his.contains(h)) { System.out.println(his.size()); StringBuilder sb = new StringBuilder(); for (Hen h2 : his) { sb.append(h2.i % n + 1).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); return true; } his.add(h); int nx = h.x; if (nx == x) { nx = h.y; } if (dfs(nx, h, his)) { return true; } his.remove(h); } } return false; } static class Hen { int x, y, i; boolean used; } }