#include using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' //#define vec vector //#define mat vector > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair pll; //typedef long double ld; typedef complex Complex; const ll INF=1e9+7; const ll MOD=998244353; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=200010; const double PI=acos(-1.0); typedef vector > mat; typedef vector vec; vector > G(MAX); vectorans(0); vectorused(MAX); ll st=-1; ll cnt=0; void dfs(ll i, ll p){ used[i]=1; for(auto e:G[i]){ if(e==p)continue; if(used[e]==1){ st=e; ans.pb(e); break; } dfs(e,i); if(st!=-1)break; } if(st==-2)return; if(st!=-1)ans.pb(i); if(st==i)st=-2; } signed main(){ ll h,w,n;cin>>h>>w>>n; mapma; ll m=-1; rep(i,n){ ll x,y;cin>>x>>y; x--;y--; G[x].pb(h+y); G[h+y].pb(x); ma[mp(x,h+y)]=i; ma[mp(h+y,x)]=i; } rep(i,h+w){ if(used[i])continue; dfs(i,-1); if(st!=-1)break; } if(st==-1){ cout<<-1<ans[1]){ ans.pb(ans[1]); REP(i,1,ans.size()-1){ cout<