#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, i, j, u, v, k, kk, a[2005], cnt = 0, cntt = 0, b[2005],
                                   dp[2005][10][10][10], x[11], ans, xx[5];
void update(int pp, int c, int q, int r, int anss) {
  if (c > q) swap(c, q);
  if (c > r) swap(c, r);
  if (q > r) swap(q, r);
  dp[pp][c][q][r] = (dp[pp][c][q][r] == -1) ? anss : min(dp[pp][c][q][r], anss);
}
void update2(int pp, int l, int r, int anss) {
  int uu[4] = {0}, i, cnttt = 4;
  for (i = 5 + cnt; i > r; i--) uu[--cnttt] = x[i];
  for (i = l - 1; i >= 5 - cntt; i--) uu[--cnttt] = x[i];
  dp[pp][uu[1]][uu[2]][uu[3]] = (dp[pp][uu[1]][uu[2]][uu[3]] == -1)
                                    ? anss
                                    : min(dp[pp][uu[1]][uu[2]][uu[3]], anss);
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  n++;
  ans = inf;
  for (i = 1; i < n; i++) scanf("%d%d", &a[i], &b[i]);
  dp[1][0][0][0] = 1 + abs(1 - a[1]);
  for (i = 2; i <= n; i++) {
    for (j = 0; j < 10; j++) {
      for (u = j; u < 10; u++) {
        for (v = u; v < 10; v++) {
          if (dp[i - 1][j][u][v] == -1) continue;
          x[5] = a[i - 1];
          cntt = 0;
          if (j > 0) xx[++cntt] = j;
          if (u > 0) xx[++cntt] = u;
          if (v > 0) xx[++cntt] = v;
          if (b[i - 1] > 0) {
            xx[++cntt] = b[i - 1];
            for (k = cntt - 1; k > 0 && xx[k] > xx[k + 1]; k--)
              swap(xx[k], xx[k + 1]);
          }
          for (k = cntt + 1; k < 5; k++) xx[k] = 0;
          for (k = 1; k <= cntt; k++)
            if (xx[k] >= x[5]) break;
          cnt = cntt - k + 1;
          cntt = cntt - cnt;
          for (k = 1; k <= cntt; k++) x[5 - cntt + k - 1] = xx[k];
          for (; k <= cntt + cnt; k++) x[5 + k - cntt] = xx[k];
          if (cnt + cntt < 4 && i < n) {
            update(i, xx[1], xx[2], xx[3],
                   dp[i - 1][j][u][v] + abs(a[i - 1] - a[i]) + 1);
          }
          if (i == n) {
            ans = min(ans, dp[i - 1][j][u][v] +
                               min(abs(a[i - 1] - x[5 - cntt]) +
                                       abs(x[5 + cnt] - x[5 - cntt]),
                                   abs(a[i - 1] - x[5 + cnt]) +
                                       abs(x[5 + cnt] - x[5 - cntt])) +
                               cnt + cntt);
            continue;
          }
          for (k = 5 - cntt; k <= 5; k++) {
            for (kk = 5; kk <= 5 + cnt; kk++) {
              if (k == 5 && kk == 5) continue;
              update2(i, k, kk,
                      dp[i - 1][j][u][v] +
                          min(abs(a[i - 1] - x[k]) + abs(x[kk] - x[k]) + kk -
                                  k + abs(x[kk] - a[i]) + 1,
                              abs(a[i - 1] - x[kk]) + abs(x[kk] - x[k]) + kk -
                                  k + abs(x[k] - a[i]) + 1));
            }
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
