import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import * H, W, N = map(int, input().split()) G = [[] for i in range(H + W)] D = dict() for i in range(N): x, y = map(int, input().split()) x, y = x - 1, y - 1 if i == 0: s, g = x, y + H G[x].append(y + H) G[y + H].append(x) D[(x, y+H)] = i + 1 D[(y+H, x)] = i + 1 seen = [0] * (H + W) seen2 = [0] * (H + W) temp = [] def dfs(s, p): for u in G[s]: if u == p: continue if seen[u]: if seen2[u] == 0: ans = [] now = u while temp: ans.append(D[(now, temp[-1])]) now = temp.pop() ans.reverse() print(len(ans)) print(*ans) exit() continue seen[u] = 1 seen2[u] = 1 temp.append(u) dfs(u, s) seen2[u] = 0 temp.pop() return for i in range(H): if seen[i]: continue temp = [i] seen[i] = 1 dfs(i, -1) print(-1)