#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 7;
int v[N][3];
int n;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
v[n * 3][1] = v[n * 3][2] = n * 2;
ll ans = 0;
for (int i = 1; i <= n * 2; i++) {
int x, y; cin >> x >> y;
if (x >= 1 and x <= n and y >= 1 and y <= 2) {
v[x][y]++;
}
else if (x >= 1 and x <= n) {
if (y > 2) {
ans += abs(y - 2);
y = 2;
}
else {
ans += abs(1 - y);
y = 1;
}
v[x][y]++;
}
else if (y >= 1 and y <= 2) {
if (x > n) {
ans += abs(n - x);
x = n;
}
else {
ans += abs(1 - x);
x = 1;
}
v[x][y]++;
}
else {
if (x <= 0 and y <= 0) {
ans += abs(x - 1);
ans += abs(y - 1);
v[1][1]++;
}
else if (x > n and y <= 0) {
ans += abs(x - n);
ans += abs(y - 1);
v[n][1]++;
}
else if (x <= 0 and y > 2) {
ans += abs(x - 1);
ans += abs(y - 2);
v[1][2]++;
}
else {
ans += abs(x - n);
ans += abs(y - 2);
v[n][2]++;
}
}
}
vector<int> a, b;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
if (!v[i][j]) {
a.push_back(i);
b.push_back(j);
}
}
}
for (int i = 1, x = 0; i <= n;) {
if (v[i][1] > 1 and v[i][2] > 1) {
ans += abs(a[x] - i);
v[a[x]][b[x]]++;
v[i][b[x]]--;
x++;
}
else if (v[i][1] > 1) {
ans += abs(i - a[x]);
ans += abs(1 - b[x]);
v[a[x]][b[x]]++;
v[i][1]--;
x++;
}
else if (v[i][2] > 1) {
if (x < a.size() and a[x] == a[x + 1]) {
swap(a[x], a[x + 1]);
swap(b[x], b[x + 1]);
}
ans += abs(i - a[x]);
ans += abs(2 - b[x]);
v[a[x]][b[x]]++;
v[i][2]--;
x++;
}
else i++;
}
cout << ans << '\n';
}