#include <iostream>

using namespace std;

int main()
{
    int n;
    int brojac = 0;
    cin >> n;
    int nizx[n];
    int nizy[n];
    for (int i=0;i<n;i++) {
        cin >> nizx[i];
        cin >> nizy[i];
    }
    for (int i=0;i<n-1;i++) {
        for (int j=0;j<n-i-1;j++) {
            if (nizx[j+1] < nizx[j]) {
                int prom = nizx[j+1];
                nizx[j+1] = nizx[j];
                nizx[j] = prom;
            }
        }
    }
    for (int i=0;i<n-1;i++) {
        for (int j=0;j<n-i-1;j++) {
            if (nizy[j+1] < nizy[j]) {
                int prom = nizy[j+1];
                nizy[j+1] = nizy[j];
                nizy[j] = prom;
            }
        }
    }

    for (int j=0;j<n-1;j++) {
        for (int i=0;i<n;i++) {
            if (nizx[i] != i+1) {
                    if (nizx[i] > i+1) {
                        nizx[i]--;
                        brojac++;
                    } else {
                        nizx[i]++;
                        brojac++;
                    }
            }
        }
    }
    for (int j=0;j<n-1;j++) {
        for (int i=0;i<n;i++) {
            if (nizy[i] != i+1) {
                    if (nizy[i] > i+1) {
                        nizy[i]--;
                        brojac++;
                    } else {
                        nizy[i]++;
                        brojac++;
                    }
            }
        }
    }
    cout << brojac;

    return 0;
}