import sys sys.setrecursionlimit(1000000) input = sys.stdin.buffer.readline def main(): H,W,N = map(int,input().split()) dic = {} Start = set([]) G = [[] for _ in range(H+W)] for i in range(N): x,y = map(int,input().split()) x -= 1; y -= 1 dic[(x,y+H)] = i+1 #1-index h = x w = y + H G[h].append(w) G[w].append(h) Start.add(h) #print(G) #print(dic) def ans_print(X): #print("X",X) ret = [] for i in range(len(X)): if i == len(X) - 1: #最後 a = X[i]; b = X[0] else: a = X[i]; b = X[i+1] if a > b: a,b = b,a ret.append(dic[(a,b)]) print(len(ret)) print(*ret) exit() def dfs(v): stack.append(v) visited[v] = len(stack) - 1 #stackの何番目にいるか for u in G[v]: if visited[u] != -1 and len(stack) - visited[u] > 2: ans_print(stack[visited[u]:]) if visited[u] != -1: continue #stack.append(u) dfs(u) stack.pop() visited[u] = -1 used = set([]) for i in Start: if i in used: continue stack = [] visited = [-1]*(H+W) dfs(i) used.add(i) #print("NEXT",stack) print(-1) if __name__ == '__main__': main()