#include <iostream>
#include <vector>

using namespace std;

int main() {

    long n;
    cin >> n;

    vector< vector<int> > mat;
    mat.resize(n);

    for (long i = 0; i < n; i++) {
        for (long j = 0; j < n; j++) {
            mat[i].resize(2);
            mat[i][j] = 0;
        }
    }

    for (long i = 0; i < n; i++) {
        long ri, ci;
        cin >> ri >> ci;

        mat[ri - 1][ci - 1] = 1;
    }

    long columns[n] = {};
    long rows[n] = {};
    long brojac = 0;

    for (long i = 0; i < n; i++) {
        for (long j = 0; j < n; j++) {
            if (mat[i][j] == 1)
                rows[i] = 1;
            if (mat[j][i] == 1) columns[i] = 1;
        }
    }

    bool jesu = true;
    for (long i = 0; i < n; i++) {
        if (columns[i] != rows[i]) jesu = false;
    }

    if (jesu) {
        cout << 0;
        return 0;
    } else {
        long sekundi = 0;
        for (long i = 0; i < n; i++) {
            for (long j = 0; j < n; j++) {
                if (mat[i][j] == 1) {
                    long index = max(i, j);
                    sekundi += index * 2 - (i + j);
                }
            }
        }

        cout << sekundi;
    }

    return 0;
}