from sys import stdin from heapq import heappush, heappop from sys import setrecursionlimit setrecursionlimit(10000000) w, h, n, *indata = map(int, stdin.read().split()) offset = 0 hq = [] xylist = [(-1,-1)] for i in range(n): y, x = indata[offset + 2*i],indata[offset + 2*i+1] heappush(hq, (y, x, i+1)) xylist.append((x,y)) par = [i for i in range(h+1)] rank = [0 for i in range(h+1)] def root(x): if par[x] == x: return x else: par[x] = root(par[x]) return par[x] def unite(x,y): karix = root(x) kariy = root(y) if karix == kariy: return 0 if rank[karix] < rank[kariy]: par[karix] = kariy else: par[kariy] = karix if rank[karix] == rank[kariy]: rank[karix] += 1 def same(x,y): return root(x) == root(y) prey = -1 prex = -1 preind = -1 samexlist = [[] for j in range(h+1)] g = [[] for i in range(n+1)] while hq: y, x, ind = heappop(hq) if prey == y: if same(prex,x): g[preind].append(ind) ind2 = samexlist[x][-1] g[ind2].append(ind) g[ind].append(ind2) que = [(ind,0)] route = [ind] check = [False for i in range(n+1)] check[ind] = True while que: now, inout = que.pop() if now == preind: route.append(now) route.append(ind) ans = [ind] lenroute = len(route) parity = 0 for i in range(1,lenroute): if parity: if xylist[ans[-1]][0] == xylist[route[i]][0]: ans.pop() ans.append(route[i]) else: ans.append(route[i]) parity = parity ^ 1 else: if xylist[ans[-1]][1] == xylist[route[i]][1]: ans.pop() ans.append(route[i]) else: ans.append(route[i]) parity = parity ^ 1 ans.pop() ansx = len(ans) L=[str(i) for i in ans] L=' '.join(L) print(L) exit() if inout == 0: que.append((now,1)) route.append(now) for i in g[now]: if not check[i]: check[i] = True que.append((i,0)) else: route.pop() else: unite(prex,x) g[ind].append(preind) g[preind].append(ind) else: prey = y if samexlist[x]: ind2 = samexlist[x][-1] g[ind2].append(ind) g[ind].append(ind2) samexlist[x].append(ind) prex = x preind = ind print("{}".format(-1))