#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >>n;
    int a[n], b[n];
    for (int i = 0; i<n; i++)
        cin >>a[i] >> b[i];
    for (int i = 0; i<n; i++)
        for (int j = i; j<n; j++)
        {
            if (a[i]>a[j])
            {
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
            if (b[i]>b[j])
            {
                int temp = b[i];
                b[i] = b[j];
                b[j] = temp;
            }
        }
    int brojac = 0;
    for (int i = 0; i<n; i++)
    {
        if (a[i]!=i+1) brojac = brojac + abs((i+1)-a[i]);
        if (b[i]!=i+1) brojac = brojac + abs((i+1)-b[i]);
    }
    cout <<brojac;
    return 0;
}