#include <bits/stdc++.h>
using namespace std;
int f[2][10000][10], a[2005], b[2005], d[4] = {1, 10, 100, 1000}, n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", a + i, b + i);
  memset(f, 0x3f, sizeof(f));
  f[0][0][1] = 0;
  for (int i = 0; i <= n; i++) {
    int k = i & 1;
    memset(f[k ^ 1], 0x3f, sizeof(f[k]));
    for (int j = 9999; j >= 0; j--) {
      for (int w = 1; w <= 9; w++) {
        if (f[k][j][w] == 0x3f3f3f3f) continue;
        int num = 0, w1[4], s1 = j;
        for (num = 0; num < 4; num++) {
          if (!s1) break;
          w1[num] = s1 % 10, s1 /= 10;
        }
        if (num < 4)
          f[k ^ 1][j + b[i + 1] * d[num]][a[i + 1]] =
              min(f[k ^ 1][j + b[i + 1] * d[num]][a[i + 1]],
                  f[k][j][w] + abs(w - a[i + 1]) + 1);
        for (int q = 0; q < num; q++) {
          s1 = 0;
          for (int r = 0; r < q; r++) s1 += w1[r] * d[r];
          for (int r = q + 1; r < num; r++) s1 += w1[r] * d[r - 1];
          f[k][s1][w1[q]] =
              min(f[k][s1][w1[q]], f[k][j][w] + abs(w - w1[q]) + 1);
        }
      }
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= 9; i++) ans = min(ans, f[n & 1][0][i]);
  printf("%d", ans);
  return 0;
}
