#include <bits/stdc++.h>
#include <climits>

#include <math.h>
using namespace std;

int main()
{
    int n,k=0;
    cin>>n;
    int kol[n],red[n],r,c;
    memset(kol,0,sizeof(kol));
    memset(red,0,sizeof(red));
    for(int i=0;i<n;i++){
            cin>>r>>c;
            kol[c-1]++;
            red[r-1]++;
    }
    for(int i=0;i<n-1;i++){
        int pr=1-kol[i];
        k+=abs(pr);
        kol[i+1]-=pr;
        pr=1-red[i];
        k+=abs(pr);
        red[i+1]-=pr;
    }
    cout<<k;
    return 0;
}