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)) if x not in even: even[x] = set() if y not in odd: odd[y] = set() for i,j in points: if i == x: even[i].add(ind+1) even[x].add(ind+1) if j == y: odd[j].add(ind+1) odd[y].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 n in graph[nxt]: 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 try: start = 1 order.append(1) seen.add(1) dfs(points[0][0], points[0][1]) print(-1) except ConnectionError: print(len(order)) print(" ".join(str(i) for i in order)) exit()