#include using namespace std; template ostream& operator<<(ostream& out, const vector &cont) { out << "["; for(const auto &x: cont) out << x<< ", "; out << "]"; return out; } #define dmp(x) cerr << #x << " = " << x << endl #define dmpn(x) cerr << #x << " = " << x <<"; " #define ff first #define ss second #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() #define int long long typedef long long ll; typedef pair pii; typedef long double ld; void solve() { int N; cin >> N; map> columns; for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; columns[x].push_back(y); } set active; int res = 0; for (auto kv : columns) { bool found_new = false; for (int y : columns[kv.ff]) { if (active.find(y) == active.end()) { found_new = true; } active.insert(y); } if (found_new) res++; } cout << res - 1 << endl; } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); solve(); return 0; }