#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int n, A[maxn], B[maxn], f[10][10][10][10][10], g[10][10][10][10][10];
inline void chkmin(int &a, int b) { a = (a < b) ? a : b; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &A[i], &B[i]);
  memset(f, inf, sizeof(f));
  f[1][0][0][0][0] = 0;
  for (int i = 1; i <= n + 1; i++) {
    memcpy(g, f, sizeof(f));
    for (int t = 1; t <= 4; t++)
      for (int j = 0; j <= 9; j++)
        for (int a = 0; a <= 9; a++)
          for (int b = 0; b <= 9; b++)
            for (int c = 0; c <= 9; c++)
              for (int d = 0; d <= 9; d++)
                if (g[j][a][b][c][d] < inf) {
                  int tmp = g[j][a][b][c][d];
                  if (a) chkmin(g[a][0][b][c][d], tmp + abs(j - a));
                  if (b) chkmin(g[b][a][0][c][d], tmp + abs(j - b));
                  if (c) chkmin(g[c][a][b][0][d], tmp + abs(j - c));
                  if (d) chkmin(g[d][a][b][c][0], tmp + abs(j - d));
                }
    if (i > n) break;
    memset(f, inf, sizeof(f));
    for (int j = 0; j <= 9; j++)
      for (int a = 0; a <= 9; a++)
        for (int b = 0; b <= 9; b++)
          for (int c = 0; c <= 9; c++)
            for (int d = 0; d <= 9; d++)
              if (g[j][a][b][c][d] < inf) {
                int tmp = g[j][a][b][c][d];
                if (!a) chkmin(f[A[i]][B[i]][b][c][d], tmp + abs(j - A[i]));
                if (!b) chkmin(f[A[i]][a][B[i]][c][d], tmp + abs(j - A[i]));
                if (!c) chkmin(f[A[i]][a][b][B[i]][d], tmp + abs(j - A[i]));
                if (!d) chkmin(f[A[i]][a][b][c][B[i]], tmp + abs(j - A[i]));
              }
  }
  int ans = inf;
  for (int i = 1; i <= 9; i++) chkmin(ans, g[i][0][0][0][0]);
  printf("%d\n", ans + 2 * n);
  return 0;
}
