from sys import stdin, setrecursionlimit setrecursionlimit(10**6) input = stdin.readline H,W,N = [int(i) for i in input().split()] odd = {} even = {} points = [] for ind in range(N): x,y = [int(i) for i in input().split()] points.append((x,y)) even.setdefault(x, {}) odd.setdefault(y, {}) for i,j in points: if i == x: even[i].setdefault(x, set()) even[x].setdefault(i, set()) even[i][x].add(ind+1) even[x][i].add(ind+1) if j == y: odd[j].setdefault(y, set()) odd[y].setdefault(j, set()) odd[j][y].add(ind+1) odd[y][j].add(ind+1) # # print(odd) # print(even) order = [] seen = set() start = 0 def dfs(x,y): global order, seen rodd = len(order)&1 graph = odd if rodd else even nxt = y if rodd else x # print(x,y,rodd,order,seen) for lst in graph[nxt]: gnl = graph[nxt][lst] for n in gnl: if n not in seen: seen.add(n) order.append(n) i,j = points[n-1] dfs(i,j) order.pop() seen.remove(n) else: if n == start and len(order) >= 4: # print(order) raise ConnectionError for ind,(i,j) in enumerate(points): # print() order.clear() seen.clear() try: start = ind+1 order.append(ind+1) seen.add(ind+1) dfs(i,j) except ConnectionError: print(len(order)) print(" ".join(str(i) for i in order)) exit() print(-1)