#include using namespace std; #define ll long long void testcase() { ll n, components = 0; cin >> n; set rows, cols; for(ll i = 0; i < n; ++i) { ll x, y; cin >> x >> y; auto rows_res = rows.insert(x); auto cols_res = cols.insert(y); if(rows_res.second && cols_res.second) components++; } cout << components - 1 << "\n"; } int main() { testcase(); }