#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //eolibraries #define lnf 3999999999999999999 #define inf 999999999 #define fi first #define se second #define pb push_back #define ll long long #define ld long double #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c).size() #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define pii pair #define rep(i,n) for(int i = 0 ; i < n ; i++) #define drep(i,n) for(int i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(int i = x ; i < n ; i++) #define vi vector #define vec(...) vector<__VA_ARGS__> #define _3yHSMG9 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) //eodefine using namespace std; const int mxn=12000; int main(){ _3yHSMG9; int h,w,n; cin>>h>>w>>n; std::map mp; vi cntx(h,0),cnty(w,0); vec(set) stx(h),sty(w); vec(pii) a(n); rep(i,n){ int x,y; cin>>x>>y; x--,y--; a[i]={x,y}; mp[a[i]]=i; stx[x].insert(i); sty[y].insert(i); cntx[x]++; cnty[y]++; } bool pok=1; pii ned={-1,-1}; rep(i,h){ if(cntx[i]%2){ if(ned.fi==-1) ned.fi=i; else pok=0; } } rep(i,w){ if(cnty[i]%2){ if(ned.se==-1) ned.se=i; else pok=0; } } if(!pok){ cout<<"-1\n"; exit(0); } vi walk; auto dfs=[&](auto self,int id,int t)->void{ // cout<