#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, xc = 0, yc = 0; cin >> n;
	vector<vector<int> > a(n, vector<int>(2));
	vector<vector<int> > b(n, vector<int>(n));
	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 2; ++j)
			cin >> a[i][j];
	for (int i = 0; i < n; ++i)
		b[a[i][0]-1][a[i][1]-1] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (b[i][j] == 1) x[i]++;
	for (int i = n - 1, o = 0; i >= 0; --i,++o)
		for (int j = 0; j < n; ++j)
			if (b[j][i] == 1) y[o]++;
	for (int i = 0; i < n; ++i) {
		int t = i;
		if (x[i] == 0) {
			for (int j = i + 1; j < n; ++j) {
				xc++;
				if (x[j] > 1) {
					x[i] = 1;
					x[j]--;
					break;
				}
			}
		}
		if (x[i] > 1) {
			for (int j = i+1; j < n; ++j) {
				xc++;
				if (x[j] == 0) {
					x[j] = 1;
					x[i]--;
					break;
				}
			}
			i--;
		}
	}
	for (int i = 0; i < n; ++i) {
		int t = i;
		if (y[i] == 0) {
			for (int j = i + 1; j < n; ++j) {
				yc++;
				if (y[j] > 1) {
					y[i] = 1;
					y[j]--;
					break;
				}
			}
		}
		if (y[i] > 1) {
			for (int j = i + 1; j < n; ++j) {
				yc++;
				if (y[j] == 0) {
					y[j] = 1;
					y[i]--;
					break;
				}
			}
			i--;
		}
	}
	int xy = xc + yc;
	cout << xy;
}