import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int[] A, B; int[][] G; bool[] vis; int[] pari; int[] ans; bool dfs(int u, int ip) { vis[u] = true; pari[u] = ip; foreach (i; G[u]) { if (i != ip) { const v = A[i] ^ B[i] ^ u; if (vis[v]) { ans ~= i; for (int w = u; w != v; ) { const j = pari[w]; ans ~= j; w = A[j] ^ B[j] ^ w; } return true; } if (dfs(v, i)) { return true; } } } return false; } void main() { try { for (; ; ) { readLong(); readLong(); const M = readInt(); long[] X = new long[M]; long[] Y = new long[M]; foreach (i; 0 .. M) { X[i] = readLong(); Y[i] = readLong(); } const xs = X.dup.sort.uniq.array; const ys = Y.dup.sort.uniq.array; const xsLen = cast(int)(xs.length); const ysLen = cast(int)(ys.length); A = new int[M]; B = new int[M]; foreach (i; 0 .. M) { A[i] = xs.lowerBound(X[i]); B[i] = xsLen + ys.lowerBound(Y[i]); } G = new int[][xsLen + ysLen]; foreach (i; 0 .. M) { G[A[i]] ~= i; G[B[i]] ~= i; } vis = new bool[xsLen + ysLen]; pari = new int[xsLen + ysLen]; pari[] = -1; ans = null; foreach (u; 0 .. xsLen + ysLen) { if (!vis[u]) { if (dfs(u, -1)) { break; } } } if (ans) { if (Y[ans[0]] != Y[ans[1]]) { ans = ans[1 .. $] ~ ans[0]; } writeln(ans.length); foreach (index, i; ans) { if (index > 0) write(" "); write(i + 1); } writeln; } else { writeln(-1); } } } catch (EOFException e) { } }