#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<vector<int>> a(3, vector<int>(n + 1));
int ans = 0, top = 0, bot = 0;
for(int i = 1; i <= 2 * n; i++){
int x, y; cin >> x >> y;
if(y <= 1) ans += 1 - y, y = 1;
else ans += y - 2, y = 2;
if(x < 1) ans += 1 - x, x = 1;
if(x > n) ans += x - n, x = n;
a[y][x]++;
}
for(int i = 1; i <= n; i++){
top += a[1][i] - 1;
bot += a[2][i] - 1;
if((top < 0 && bot > 0) || (top > 0 && bot < 0)){
if(abs(top) < abs(bot)){
ans += abs(top);
bot += top;
top = 0;
}else{
ans += abs(bot);
top += bot;
bot = 0;
}
}
ans += abs(top + bot);
}
cout << ans;
}