#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 3e18, MOD = 1e9 + 7;
void solve();
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int q = 1;
while (q--) {
solve();
}
}
void solve() {
ll n; cin >> n;
vector<pair<ll, ll>> a(2 * n + 1);
for (int i = 1; i <= 2 * n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin() + 1, a.end());
vector<vector<ll>> dp(2 * n + 1, vector<ll>(n + 1, INF));
dp[0][0] = 0;
for (int i = 1; i <= 2 * n; i++) {
for (int j = 0; j <= min(ll(i), n); j++) {
dp[i][j] = min(dp[i][j], dp[i - 1][j] + abs(2 - a[i].second) + abs(i - j - a[i].first));
if (j != 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + abs(1 - a[i].second) + abs(j - a[i].first));
}
}
}
cout << dp[2 * n][n];
}