#include <bits/stdc++.h>
using namespace std;
int n;
int dp[2007][10][800];
vector<pair<int, int> > pes;
int cod[10][10][10][10];
int go(int curr, int andar, int c1, int c2, int c3, int c4) {
  if (andar < 1 or andar > 9) return 0x3f3f3f3f;
  vector<int> v = {c1, c2, c3, c4};
  sort((v).begin(), (v).end());
  int &ret = dp[curr][andar][cod[v[0]][v[1]][v[2]][v[3]]];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i < 4; i++) {
    if (v[i] == andar) {
      ret++;
      v[i] = 0;
    }
    if (curr < pes.size() and v[i] == 0 and pes[curr].first == andar) {
      ret++;
      v[i] = pes[curr++].second;
    }
  }
  if (curr == pes.size() and v[0] + v[1] + v[2] + v[3] == 0) return ret;
  int val = 0x3f3f3f3f;
  sort((v).begin(), (v).end());
  for (int i = 0; i < 4; i++) {
    if (v[i])
      val =
          min(val, abs(andar - v[i]) + go(curr, v[i], v[0], v[1], v[2], v[3]));
  }
  if (v[0] == 0 and curr < pes.size())
    val = min(val, abs(andar - pes[curr].first) +
                       go(curr, pes[curr].first, v[0], v[1], v[2], v[3]));
  return ret += val;
}
int main(int argc, char const *argv[]) {
  int cnt = 0;
  for (int i = 0; i <= 9; i++) {
    for (int j = i; j <= 9; j++) {
      for (int k = j; k <= 9; k++) {
        for (int l = k; l <= 9; l++) {
          cod[i][j][k][l] = cnt++;
        }
      }
    }
  }
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; i++) {
    pair<int, int> p;
    cin >> p.first >> p.second;
    pes.push_back(p);
  }
  cout << pes[0].first - 1 + go(0, pes[0].first, 0, 0, 0, 0) << endl;
  return 0;
}
