#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int n, aa[N], bb[N], f[2][10][10][10][10][10], ans;
inline void up(int &x, int y) { x = min(x, y); }
inline int read() {
  int num = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) num = (num << 1) + (num << 3) + ch - '0', ch = getchar();
  return num;
}
int main() {
  memset(f, 0x3f, sizeof(f));
  ans = f[0][1][0][0][0][0], f[0][1][0][0][0][0] = 0;
  n = read();
  for (int i = (1); i <= (n); ++i) aa[i] = read(), bb[i] = read();
  for (int i = (1); i <= (n + 1); ++i) {
    int now = i & 1, las = i - 1 & 1;
    for (int k = (1); k <= (4); ++k)
      for (int j = (1); 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 (f[las][j][a][b][c][d] < ans) {
                  if (a)
                    up(f[las][a][0][b][c][d],
                       f[las][j][a][b][c][d] + abs(j - a) + 1);
                  if (b)
                    up(f[las][b][a][0][c][d],
                       f[las][j][a][b][c][d] + abs(j - b) + 1);
                  if (c)
                    up(f[las][c][a][b][0][d],
                       f[las][j][a][b][c][d] + abs(j - c) + 1);
                  if (d)
                    up(f[las][d][a][b][c][0],
                       f[las][j][a][b][c][d] + abs(j - d) + 1);
                }
    if (i > n) break;
    for (int j = (1); 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) f[i & 1][j][a][b][c][d] = ans;
    for (int j = (1); 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 (f[las][j][a][b][c][d] < ans) {
                if (!a)
                  up(f[now][aa[i]][bb[i]][b][c][d],
                     f[las][j][a][b][c][d] + abs(j - aa[i]) + 1);
                if (!b)
                  up(f[now][aa[i]][a][bb[i]][c][d],
                     f[las][j][a][b][c][d] + abs(j - aa[i]) + 1);
                if (!c)
                  up(f[now][aa[i]][a][b][bb[i]][d],
                     f[las][j][a][b][c][d] + abs(j - aa[i]) + 1);
                if (!d)
                  up(f[now][aa[i]][a][b][c][bb[i]],
                     f[las][j][a][b][c][d] + abs(j - aa[i]) + 1);
              }
  }
  for (int i = (1); i <= (9); ++i) ans = min(ans, f[n & 1][i][0][0][0][0]);
  cout << ans;
  return 0;
}
