import sys input = sys.stdin.buffer.readline h, w, n = map(int, input().split()) num = 10 ** 5 graph = [[] for _ in range(2 * num)] start = set() edges = {} e = {} for i in range(n): a, b = map(int, input().split()) a, b = a - 1, b - 1 b += num graph[a].append(b) graph[b].append(a) start.add(a) edges[(a, b)] = i edges[(b, a)] = i e[i] = (a, b) used = [0] * num * 2 # graph and n is necessary def dfs(start): par = [-1] * num * 2 depth = [-1] * num * 2 size = [0] * num * 2 stack = [] stack.append(~start) stack.append(start) euler = [] while stack: v = stack.pop() if v >= 0: d = depth[v] used[v] = 1 euler.append(v) for u in graph[v]: if par[v] == u: continue if used[u]: euler.append(u) return 1, euler par[u] = v stack.append(~u) stack.append(u) else: a = ~v if euler: euler.pop() return 0, [] for s in start: if used[s]: continue flag, euler = dfs(s) if flag: ans = [] for u, v in zip(euler, euler[1:]): ans.append(edges[(u, v)] + 1) if len(ans) % 2: continue if len(ans) >= 4: a, b = ans[0], ans[1] x1, y1 = e[a - 1] x2, y2 = e[b - 1] if y1 == y2: ans = ans[::-1] print(len(ans)) print(*ans) exit() print(-1)