#include using namespace std; int main(){ int H, W, N; cin >> H >> W >> N; vector x(N), y(N); vector> G(H + W); map, int> m; for(int i = 0; i < N; i++) { cin >> x[i] >> y[i]; x[i]--; y[i]--; G[x[i]].push_back(H + y[i]); G[H + y[i]].push_back(x[i]); m[{x[i], H + y[i]}] = i; } vector used(H + W); vector par(H + W, -1); bool f = false; auto dfs = [&](auto dfs, int now, int num, int p) -> void{ used[now] = num; if(f) true; for(int to : G[now]){ if(f) return; if(p == to) continue; if(used[to] == -1) continue; if(used[to] > 0 && num - used[to] >= 3){ f = true; int t = now; vector ans; ans.push_back(m[{min(now, to), max(now, to)}]); while(par[t] != -1){ ans.push_back(m[{min(t, par[t]), max(t, par[t])}]); t = par[t]; } reverse(ans.begin(), ans.end()); cout << ans.size() << endl; for(int i = 0; i < (int)ans.size(); i++){ if(i == (int)ans.size() - 1) cout << ans[i] + 1 << endl; else cout << ans[i] + 1 << ' '; } return; } par[to] = now; dfs(dfs, to, num + 1, now); } used[now] = -1; }; for(int i = 0; i < H; i++){ if(used[i] == 0) dfs(dfs, i, 1, -1); } if(!f) cout << -1 << endl; }