from collections import deque H, W, N = map(int, input().split()) rows = [[] for _ in range(H)] columns = [[] for _ in range(W)] points = [] for i in range(N): x, y = (int(x) - 1 for x in input().split()) points.append((x, y)) rows[x].append(i) columns[y].append(i) parent = [None] * N nonvisited = set(range(N)) while nonvisited: v0 = nonvisited.pop() d = deque([(v0, -1)]) while d: v, p = d.pop() parent[v] = p nonvisited.discard(v) row, col = points[v] for x in rows[row] + columns[col]: if x == v or x == p: continue if x in nonvisited: d.append((x, v)) else: # cycle found ans = [v + 1] y = parent[v] while y != v and y != -1: ans.append(y + 1) y = parent[y] print(len(ans)) print(*ans) exit() print(-1)