#include <iostream>
#include <stdlib.h>

struct coin {
	int row = 0;
	int clm = 0;
};

int main(int argc, char* argv[]) {
	
	int n;
	std::cin >> n;
	coin grid[n];
	
	for (int i = 0; i < n; i++) {
		std::cin >> grid[i].row;
		std::cin >> grid[i].clm;
	}
	
	int seconds = 0;
	for (int x = 0; x < n; x++) {
		
		for (int y = 0; y < n; y++) {
			
			if (&grid[x] != &grid[y]) {
				
				if (grid[x].row == grid[y].row) {
					
					while (true) {
						bool repeat = false;
						grid[y].row = rand() % n + 1;
						
						for (int z = 0; z < n; z++) {
							if (&grid[y] != &grid[z]) {
								if (grid[y].row == grid[z].row) {
									repeat = true;
									break;
								}
							}
						}
						
						if (!repeat) {
							break;
						}
					}
					
					seconds++;
				}
				
				if (grid[x].clm == grid[y].clm) {
					
					
					while (true) {
						bool repeat = false;
						grid[y].clm = rand() % n + 1;
						
						for (int z = 0; z < n; z++) {
							if (&grid[y] != &grid[z]) {
								if (grid[y].clm == grid[z].clm) {
									repeat = true;
									break;
								}
							}
						}
						
						if (!repeat) {
							break;
						}
					}
					
					seconds++;
				}
			}
		}
	}
	
	// // print sorted grid
	// for (int i = 0; i < n; i++) {
	// 	std::cout << grid[i].row << " " << grid[i].clm << std::endl;
	// }
	
	std::cout << seconds << std::endl;
	
    return 0;
}