#include <stdio.h>
#include <stdlib.h>

int main()
{
    long N, i, j;
    long r, c;
    scanf("%ld", &N);
    long arr[N][N];
    for(i = 0; i < N; i++)
        for(j = 0; j < N; j++)
            arr[i][j] = 0;
    for(i = 0; i < N; i++){
        scanf("%ld %ld", &r, &c);
        r--;
        c--;
        arr[r][c] = 1;
    }
    long p = 0;
    long count[1];
    count[0] = 0;
    popuni1(N, arr, 0, count);
    p += count[0];
    count[0] = 0;
    popuni2(N, arr, 0, count);
    p += count[0];
    printf("%ld ", p);
}
void popuni1(long N, long arr[N][N], long v, long count[])
{
    long i;
    if(v == N-1){
        int provera = 0;
        for(i = 0; i < N; i++)
        {
            if(sum1(N, v, arr) != 1) provera = 1;
        }
        if(provera == 1) popuni1(N, arr, 0, count);
    }
    else
    {
        while(sum1(N, v, arr) > 1)
        {
            for(i = 0; i < N; i++){
                if(arr[i][v] == 1 && arr[i][v+1]==0)
                {
                    arr[i][v] = 0;
                    arr[i][v+1] = 1;
                    count[0]++;
                    break;
                }
            }
        }
        while(sum1(N, v, arr) == 0)
        {
            for(i = 0; i < N; i++){
                if(arr[i][v+1] == 1)
                {
                    arr[i][v] = 1;
                    arr[i][v+1] = 0;
                    count[0]++;
                    break;
                }
            }
        }
        popuni1(N, arr, v+1, count);
    }
}

int sum1(long N, long v, long arr[N][N])
{
    long s = 0, i;
    for(i = 0; i < N; i++)
    {
        s+=arr[i][v];
    }
    return s;
}

void popuni2(long N, long arr[N][N], long v, long count[])
{
    long i;
    if(v == N-1){
        int provera = 0;
        for(i = 0; i < N; i++)
        {
            if(sum2(N, v, arr) != 1) provera = 1;
        }
        if(provera == 1) popuni2(N, arr, 0, count);
    }
    else
    {
        while(sum2(N, v, arr) > 1)
        {
            for(i = 0; i < N; i++){
                if(arr[v][i] == 1 && arr[v+1][i]==0)
                {
                    arr[v][i] = 0;
                    arr[v+1][i] = 1;
                    count[0]++;
                    break;
                }
            }
        }
        while(sum2(N, v, arr) == 0)
        {
            for(i = 0; i < N; i++){
                if(arr[v+1][i] == 1)
                {
                    arr[v][i] = 1;
                    arr[v+1][i] = 0;
                    count[0]++;
                    break;
                }
            }
        }
        popuni2(N, arr, v+1, count);
    }
}

int sum2(long N, long v, long arr[N][N])
{
    long s = 0, i;
    for(i = 0; i < N; i++)
    {
        s+=arr[v][i];
    }
    return s;
}