#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){ par[to] = now; f = true; int t = now; vector ans; ans.push_back(m[{min(now, to), max(now, to)}]); while(par[t] != now){ ans.push_back(m[{min(t, par[t]), max(t, par[t])}]); t = par[t]; } reverse(ans.begin(), ans.end()); cout << ans.size() << endl; int ofs = 0; int n = ans.size(); for(int i = 0; i < n; i++){ if(i % 2 == 0){ if(y[ans[i]] != y[ans[(i + 1) % n]]){ ofs = 1; break; } } else{ if(x[ans[i]] != x[ans[(i + 1) % n]]) { ofs = 1; break; } } } for(int i = 0; i < n; i++){ if(i == n - 1) cout << ans[(i + ofs) % n] + 1 << endl; else cout << ans[(i + ofs) % n] + 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; }