#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005, inf = 0x3f3f3f3f;
const short oo = 25000;
int n;
short c[MAX], a[MAX];
short f[MAX][MAX][2][10];
short tinh(short i, short X, bool tt, short fl) {
  if (f[i][X][tt][fl] != -1) return f[i][X][tt][fl];
  if (i > n) return oo;
  f[i][X][tt][fl] = oo;
  short b[4], Y, temp;
  Y = X;
  b[0] = Y % 10;
  Y /= 10;
  b[1] = Y % 10;
  Y /= 10;
  b[2] = Y % 10;
  Y /= 10;
  b[3] = tt * c[i];
  sort(b, b + 4);
  if (!tt) {
    if (b[1])
      f[i][X][tt][fl] = tinh(i + 1, X, 1, a[i + 1]) + abs(a[i + 1] - fl);
    else {
      b[1] = c[i + 1];
      sort(b, b + 4);
      Y = b[1] * 100 + b[2] * 10 + b[3];
      f[i][X][tt][fl] = tinh(i + 1, Y, 0, a[i + 1]) + abs(a[i + 1] - fl);
      for (short j = 0; j < 4; j++)
        if (b[j] == c[i + 1]) {
          b[j] = 0;
          break;
        }
      sort(b, b + 4);
    }
  }
  for (short j = 0; j < 4; j++) {
    if (b[j]) {
      Y = 0;
      for (short u = 0; u < 4; u++)
        if (u != j) {
          Y = Y * 10 + b[u];
        }
      temp = tinh(i, Y, 0, b[j]) + abs(b[j] - fl);
      f[i][X][tt][fl] = min(f[i][X][tt][fl], temp);
    }
  }
  return f[i][X][tt][fl];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(f, -1, sizeof f);
  for (int i = 1; i <= n; i++) cin >> a[i] >> c[i];
  for (int i = 1; i <= 9; i++) f[n][0][0][i] = 0;
  cout << tinh(0, 0, 0, 1) + n * 2;
}
