#include <iostream>
#include <limits>
#include <cmath>
#include <iomanip>;

using namespace std;

typedef numeric_limits<streamsize> ignore_t;

int main() 
{
	int N{};
	scanf_s("%d", &N);

	int sec{};

	int** tabla = new int*[N + 1];

	for (int i{}; i <= N; ++i) 
	{
		tabla[i] = new int[N + 1];
	}

	for (int i{1}; i <= N; ++i) 
	{
		int x{}, y{};

		cin >> x;
		cin >> y;
		cin.ignore(ignore_t::max(), '\n');

		tabla[x][y] = 1;
		tabla[x][0] = 1;
		tabla[0][y] = 1;
	}

	for (int i{1}; i <= N; ++i) 
	{
		if (tabla[i][0] == 1) 
		{
			int br{};
			for (int j{1}; j <= N; ++j) 
			{
				if (tabla[i][j] == 1)
					++br;
				if (br >= 2) 
				{
					if (tabla[i - 1][j] != 1 && tabla[i - 1][0] != 1)
					{
						int temp = tabla[i][j];
						tabla[i][j] = tabla[i - 1][j];
						tabla[i - 1][j] = tabla[i][j];
						tabla[i - 1][0] = 1;
						++sec;
					}
					else if (tabla[i + 1][j] != 1 && tabla[i + 1][0] != 1)
					{
						int temp = tabla[i][j];
						tabla[i][j] = tabla[i + 1][j];
						tabla[i + 1][j] = tabla[i][j];
						tabla[i + 1][0] = 1;
						++sec;
					}
				}
					
			}
		}
	}

	cout << sec;
	
	cin.clear();
	cin.ignore(ignore_t::max(), '\n');
	cin.get();

	return 0;
}