#include #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w, n; cin >> h >> w >> n; vector> to(h + w); rep(i, n) { int x, y; cin >> x >> y; x--, y--; to[x].emplace_back(h + y, i + 1); to[h + y].emplace_back(x, i + 1); } vector visited(h + w); vector

path; auto dfs = [&](auto&& self, int u, int p=-1) -> void { if (visited[u]) { VI ans; ans.push_back(p); while(path.back().first != u) { ans.push_back(path.back().second); path.pop_back(); } int sz = ans.size(); cout << sz << '\n'; rep(i, sz) cout << ans[i] << " \n"[i + 1 == sz]; exit(0); } visited[u] = true; path.emplace_back(u, p); for(auto [v, eid]: to[u]) if (eid != p) { self(self, v, eid); } }; rep(i, h) if (!visited[i]) dfs(dfs, i); cout << -1 << endl; }