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