#include <iostream>
#include <math.h>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	long int n,i;
	cin>>n;
	long int r[n+1],c[n+1];
	for(i=1;i<=n;i++) {
		r[i]=0;
		c[i]=0;
	}
	
	for(i=1;i<=n;i++) {
		int a,b;
		cin>>a>>b;
		r[a]++; c[b]++;
	}
	i=0;
	
	for(i=2;i<=n;i++){
		
		r[i]=r[i]+r[i-1];
		c[i]=c[i]+c[i-1];
	}
	long long br=0;
	for(i=1;i<=n;i++){
		br+=abs(c[i]-i);
		br+=abs(r[i]-i);
	}
	cout<<br;
	
	
	return 0;
}