import sys sys.setrecursionlimit(1000000) h, w, n = map(int, input().split()) edge = [[] for _ in range(h + w)] for idx in range(n): x, y = [int(i) - 1 for i in input().split()] y = y + h edge[x].append((y, idx)) edge[y].append((x, idx)) visited = [False] * (h + w) def output(t, is_h): t.reverse() if not is_h: t = t[1:] + t[:1] print(len(t)) print(*(i+1 for i in t)) def dfs(i, prev=-1): if visited[i]: return [], i is_h = i < h visited[i] = True for j, idx in edge[i]: if j == prev: continue t, start = dfs(j, i) if start != -1: t.append(idx) if start == i: output(t, is_h) exit() return t, start return [], -1 for i in range(h + w): if not visited[i]: dfs(i) print(-1)