#include #include using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() const long long MOD = 1000000007; const long long INF = 9999999999999999; using ll = long long; using mint = modint1000000007; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b>N; ll H[200200] = {}; ll W[200200] = {}; rep(i,N){ ll a,b; cin>>a>>b; H[a]++; W[b]++; } ll d = 0; ll tigau = 0; rep(i,200200){ if(H[i] != W[i]){ tigau++; } } if(tigau > 2){ cout << 0 << endl; } else if(tigau == 0){ ll ans = 0; rep(i,200200){ if(H[i]>0){ ans++; } } cout << ans << endl; } else if(tigau == 2){ cout << 1 << endl; } return 0; }