#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
int d[10][10][10][10][10], f[10][10][10][10][10];
int a[2005], b[2005], n, ans;
void up(int &x, int y) {
  if (x > y) x = y;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read(), b[i] = read();
  for (int j = 1; j <= 9; j++)
    for (int t1 = 0; t1 <= 9; t1++)
      for (int t2 = 0; t2 <= 9; t2++)
        for (int t3 = 0; t3 <= 9; t3++)
          for (int t4 = 0; t4 <= 9; t4++) d[j][t1][t2][t3][t4] = inf;
  d[1][0][0][0][0] = 0;
  for (int i = 1; i <= n + 1; i++) {
    for (int k = 1; k <= 4; k++)
      for (int j = 1; j <= 9; j++)
        for (int t1 = 0; t1 <= 9; t1++)
          for (int t2 = 0; t2 <= 9; t2++)
            for (int t3 = 0; t3 <= 9; t3++)
              for (int t4 = 0; t4 <= 9; t4++)
                if (d[j][t1][t2][t3][t4] < inf) {
                  if (t1)
                    up(d[t1][0][t2][t3][t4],
                       d[j][t1][t2][t3][t4] + abs(j - t1) + 1);
                  if (t2)
                    up(d[t2][t1][0][t3][t4],
                       d[j][t1][t2][t3][t4] + abs(j - t2) + 1);
                  if (t3)
                    up(d[t3][t1][t2][0][t4],
                       d[j][t1][t2][t3][t4] + abs(j - t3) + 1);
                  if (t4)
                    up(d[t4][t1][t2][t3][0],
                       d[j][t1][t2][t3][t4] + abs(j - t4) + 1);
                }
    if (i > n) break;
    for (int j = 1; j <= 9; j++)
      for (int t1 = 0; t1 <= 9; t1++)
        for (int t2 = 0; t2 <= 9; t2++)
          for (int t3 = 0; t3 <= 9; t3++)
            for (int t4 = 0; t4 <= 9; t4++) f[j][t1][t2][t3][t4] = inf;
    for (int j = 1; j <= 9; j++)
      for (int t1 = 0; t1 <= 9; t1++)
        for (int t2 = 0; t2 <= 9; t2++)
          for (int t3 = 0; t3 <= 9; t3++)
            for (int t4 = 0; t4 <= 9; t4++) {
              if (!t1)
                up(f[a[i]][b[i]][t2][t3][t4],
                   d[j][t1][t2][t3][t4] + abs(j - a[i]) + 1);
              if (!t2)
                up(f[a[i]][t1][b[i]][t3][t4],
                   d[j][t1][t2][t3][t4] + abs(j - a[i]) + 1);
              if (!t3)
                up(f[a[i]][t1][t2][b[i]][t4],
                   d[j][t1][t2][t3][t4] + abs(j - a[i]) + 1);
              if (!t4)
                up(f[a[i]][t1][t2][t3][b[i]],
                   d[j][t1][t2][t3][t4] + abs(j - a[i]) + 1);
            }
    for (int j = 1; j <= 9; j++)
      for (int t1 = 0; t1 <= 9; t1++)
        for (int t2 = 0; t2 <= 9; t2++)
          for (int t3 = 0; t3 <= 9; t3++)
            for (int t4 = 0; t4 <= 9; t4++)
              d[j][t1][t2][t3][t4] = f[j][t1][t2][t3][t4];
  }
  ans = inf;
  for (int i = 1; i <= 9; i++) up(ans, d[i][0][0][0][0]);
  return 0 * printf("%d\n", ans);
}
