#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int l[200020] = {}, r[200020] = {}; set st; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int h, w; cin >> h >> w; st.insert(h); int m = l[w]; if (r[h] == 0) { l[h]++; } else { r[h]--; } if (m == 0) { r[w]++; } else { l[w]--; } } int l1 = 0, r1 = 0; for (int i = 1; i <= 200000; i++) { l1 += l[i]; r1 += r[i]; } if (l1 == 0 && r1 == 0) { cout << st.size() << endl; } else if (l1 == 1 && r1 == 1) { cout << 1 << endl; } else { cout << 0 << endl; } }