#include "bits/stdc++.h" #include "atcoder/all" using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } vectorto[200005]; bool use[200005]; bool b; vectorans; void dfs(int v, int root, int p = -1) { use[v] = true; for (auto e : to[v]) { if (root == e) b = true; if (b)break; if (use[e])continue; ans.push_back(e); dfs(e, root, v); if (b)break; ans.pop_back(); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h, w, n; cin >> h >> w >> n; map>mpx, mpy; vectorx(n), y(n); rep(i, n) { cin >> x[i] >> y[i]; x[i]--; y[i]--; mpx[x[i]].insert(i); mpy[y[i]].insert(i); } scc_graph ss(2 * n); rep(i, n) { for (auto idx : mpy[y[i]]) { if (i == idx) continue; to[i * 2].push_back(idx * 2 + 1); ss.add_edge(i * 2, idx * 2 + 1); } for (auto idx : mpx[x[i]]) { if (i == idx) continue; to[i * 2 + 1].push_back(idx * 2); ss.add_edge(i * 2 + 1, idx * 2); } } vector> scc = ss.scc(); rep(i, scc.size()) { if (1 == scc[i].size())continue; int fir = -1; rep(j, scc[i].size()) { if (0 == scc[i][j] % 2)fir = scc[i][j]; } rep(j, n * 2)use[j] = true; rep(j, scc[i].size())use[scc[i][j]] = false; ans.push_back(fir); dfs(fir, fir); cout << ans.size() << endl; rep(j, ans.size()) cout << ans[j] / 2 + 1 << " "; return 0; } cout << -1 << endl; return 0; }