#include <bits/stdc++.h>
using namespace std;
int x[2010], y[2010];
int n;
int mapa[15][15][15][15];
map<vector<int>, int> dp[15][2015];
int solve(int lvl, int pos, vector<int> v1) {
  if (pos == n && (v1[0] + v1[1] + v1[2] + v1[3]) == 0) {
    return 0;
  }
  if (dp[lvl][pos].count(v1)) return dp[lvl][pos][v1];
  int ans = 1e8;
  for (int l = 1; l <= 9; l++) {
    int p = pos;
    int t = 0;
    vector<int> v = v1;
    for (int i = 0; i < 4; i++) {
      if (v[i] == l) {
        v[i] = 0;
        t++;
      }
    }
    for (int i = 0; p < n && i < 4; i++) {
      if (l == x[p] && v[i] == 0) {
        t++;
        v[i] = y[p];
        p++;
      }
    }
    sort(v.begin(), v.end());
    if (p == pos && v == v1) continue;
    ans = min(ans, solve(l, p, v) + abs(lvl - l) + t);
  }
  return dp[lvl][pos][v1] = ans;
}
int32_t main() {
  int cont = 0;
  for (int i = 1; i <= 9; i++)
    for (int j = i; j <= 9; j++)
      for (int k = j; k <= 9; k++)
        for (int l = k; l <= 9; l++) mapa[i][j][k][l] = ++cont;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  cout << solve(1, 0, {0, 0, 0, 0}) << '\n';
  return 0;
}
