#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n, x[200000], y[200000], sum = 0, br = 0;
    cin >> n;
    bool bo = false;
    int prvaDig = 0, drugaDig = 0;


    for(int i = 0 ; i < n ; i++){
            cin >> x[i] >> y[i];
            if(x[i] == 1 || y[i] == 1) bo == true;
            sum += x[i] + y[i];
    }

    if(sum == n*(n + 1) && bo)
        cout << 0;

    else
    {

        int suma1 = 0, suma2 = 0;
        for(int i = 0 ; i < n ; i++){
            for(int j = i + 1 ; j < n ; j++){
                if(x[i] == x[j]) suma1++;
                if(y[i] == y[j]) suma2++;
            }
        }
        if(suma1 == n) br += 2;
        else if(suma2 == n) br += 2;
        cout << abs(n*(n+1)-sum) + br;

    }

}