#include <iostream>
#include <vector>

using namespace std;
//zadatak c

int NumOfD(int n, vector<int> &a, vector<int> &arr) {
	int b = 0;
	int i, j;
	bool f;
	vector<bool> found;
	for (i = 0; i < n; i++) {
		found.push_back(0);
	}

	for (i = 0; i < n; i++) {
		f = 0;
		if (found[i] == 0) {
			for (j = i + 1; j < n; j++) {
				if (a[i] == a[j]) {
					found[i] = 1;
					found[j] = 1;
					if (f == 0) {
						f = 1;
						arr[b] = i;
						b++;
					}
					
					arr[b] = j;
					b++;
				}
			}
		}

	}
	return b;
}


int main() {

	int i, b, j;
	int n;
	int tempr, tempc;
	vector<int> r;
	vector<int> c;
	int d1, d2;
	vector<int> duplr;
	vector<int> duplc;
	int kol;


	cin >> n;
	b = 0;

	for (int i = 0; i < n; i++) {
		cin >> tempr >> tempc;
		r.push_back(tempr);
		c.push_back(tempc);

	}
	for (int i = 0; i < n; i++) {
		duplr.push_back(-1);
		duplc.push_back(-1);

	}
	//isprazniti memoriju u duplr i c?
	d1 = 0;
	d2 = 0;
	d1 = NumOfD(n, r, duplr);
	d2 = NumOfD(n, c, duplc);

	kol = 0;

	for (i = 0; i < d1; i++) {
		for (j = 0; j < d2; j++) {
			if (duplr[i] == duplc[j]) {
				kol++;
			}
		}
	}


	if ((d1 == 0) && (d2 == 0)) {
		cout << '0' << endl;
	}
	else if ((d1 == 0) || (d2 == 0)) {
		if (d1 != 0) {
			b = d1 - 1;
			cout << b << endl;
		}
		else {
			b = d2 - 1;
			cout << b << endl;
		}
	}
	else if (d1 > d2) {
		b = d1 - kol;
		cout << b << endl;
	}
	else {
		b = d2 - kol;
		cout << b << endl;
	}

	return 0;
}