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] = 1 for u in G[v]: if u == stack[0] and len(stack) > 2: ans_print(stack) if visited[u] == 1: continue #stack.append(u) dfs(u) stack.pop() visited[u] = 0 for i in Start: stack = [] visited = [0]*(H+W) dfs(i) #print("NEXT",stack) print(-1) if __name__ == '__main__': main()