#include <bits/stdc++.h>

#define endl "\n"
#define ll long long
#define all(x) x.begin(),x.end()

using namespace std;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    int n; cin >> n;
    vector<pair<int,int>> v(n);

    for(auto& x:v) cin >> x.first >> x.second;

    sort(all(v));
    long long ans=0;

    int k=1;
    for(auto x:v) {
        ans+=abs(x.first-k);
        k++;
    }

    sort(all(v),sortbysec);

    k=1;
    for(auto x:v) {
        ans+=abs(x.second-k);
        k++;
    }

    cout << ans << endl;

    return 0;
}