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()) rows[x].append(i) columns[y].append(i) G = [[] for _ in range(N)] for row in rows: for i in range(len(row) - 1): G[row[i]].append(row[i + 1]) G[row[i + 1]].append(row[i]) for column in columns: for i in range(len(column) - 1): G[column[i]].append(column[i + 1]) G[column[i + 1]].append(column[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) for x in G[v]: 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)