#include <bits/stdc++.h>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    int n , y , x ;
    cin >> n ;
    int vrste[n];
    int kolone[n];
    vector<pair<int,int> > v ;
    for (int i = 0 ; i < n ; i++ ) {
        cin >> y >> x ;
        v.push_back(make_pair(y,x));
    }
    sort(v.begin(),v.end());
    unsigned int c = 0 ;
    vector<int>r ;
    for (int i = 0 ; i < n ; i++ ) {
        c+= abs(i-v[i].first+1);
        v[i].first = i ;
        r.push_back(v[i].second);
    }
    sort(r.begin(),r.end());
    for (int i = 0 ; i < n ; i++ ) {
        c+= abs(i-r[i]+1);
    }
    
    cout << c ;
}