#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, low, high, h, a[2100], b[2100], f[2100][10][10][10], c[5], d[5];
void update(int &x, int k) {
  if (x > k) x = k;
}
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[1][0][0][0] = a[1];
  for (int i = 1; i < n; i++)
    for (int x = 0; x <= 9; x++)
      for (int y = 0; y <= 9; y++)
        for (int z = 0; z <= 9; z++) {
          if (f[i][x][y][z] == INF) continue;
          for (int k = 1; k <= 9; k++) {
            h = abs(k - a[i]) + abs(a[i + 1] - k);
            d[0] = d[1] = d[2] = d[3] = d[4] = 0;
            c[1] = b[i];
            c[2] = x;
            c[3] = y;
            c[4] = z;
            low = min(k, min(a[i], a[i + 1]));
            high = max(k, max(a[i], a[i + 1]));
            for (int t = 1; t <= 4; t++)
              if (c[t] >= low && c[t] <= high)
                h++;
              else if (c[t])
                d[++d[0]] = c[t];
            if (d[0] <= 3)
              update(f[i + 1][d[1]][d[2]][d[3]], f[i][x][y][z] + 1 + h);
          }
        }
  int ans = INF;
  for (int x = 0; x <= 9; x++)
    for (int y = 0; y <= 9; y++)
      for (int z = 0; z <= 9; z++) {
        if (f[n][x][y][z] == INF) continue;
        for (int p = 1; p <= 9; p++)
          for (int q = 1; q <= 9; q++) {
            h = abs(p - a[n]) + abs(q - p);
            high = max(a[n], max(p, q));
            low = min(a[n], min(p, q));
            c[1] = b[n];
            c[2] = x;
            c[3] = y;
            c[4] = z;
            for (int i = 1; i <= 4; i++) {
              if (c[i] && (c[i] < low || c[i] > high)) {
                h = -1;
                break;
              }
              if (c[i]) h++;
            }
            if (h >= 0) update(ans, f[n][x][y][z] + h);
          }
      }
  cout << ans;
  return 0;
}
