#include <bits/stdc++.h>
using namespace std;
int dp[2][10000];
int dpi[10000], tot = 0;
int n, a[2001], b[2001], p[5];
const int inf = 40000;
int mysort(int x, int l, int r, int ad) {
  int ans = 0, ps[5], p = 0, tmp;
  while (x) {
    tmp = x % 10;
    x /= 10;
    if (tmp < l || tmp > r) ps[p++] = tmp;
  }
  ps[p++] = ad;
  if (p == 5) return -1;
  sort(ps, ps + p);
  for (int i = 0; i < p; i++) {
    ans = ans * 10 + ps[i];
  }
  return ans;
}
int suan(int x, int y) {
  int minl = y, maxl = y;
  while (x) {
    int tmp = x % 10;
    x /= 10;
    minl = min(minl, tmp);
    maxl = max(maxl, tmp);
  }
  return min(y - minl + maxl - minl, maxl - y + maxl - minl);
}
void init() {
  for (int i1 = 0; i1 <= 9; i1++)
    for (int i2 = i1; i2 <= 9; i2++)
      for (int i3 = i2; i3 <= 9; i3++)
        for (int i4 = i3; i4 <= 9; i4++)
          dpi[tot++] = i1 * 1000 + i2 * 100 + i3 * 10 + i4;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  for (int ji = 0; ji < tot; ji++) dp[1][dpi[ji]] = inf;
  dp[1][b[1]] = a[1] - 1;
  for (int i = 1; i < n; i++) {
    for (int ji = 0; ji < tot; ji++) dp[(i + 1) & 1][dpi[ji]] = inf;
    int minl = min(a[i], a[i + 1]), maxl = max(a[i], a[i + 1]);
    for (int l = 1; l <= minl; l++) {
      for (int r = maxl; r <= 9; r++) {
        for (int ji = 0; ji < tot; ji++) {
          int j = dpi[ji];
          if (dp[i & 1][j] == inf) continue;
          int tmpj = mysort(j, l, r, b[i + 1]);
          if (tmpj == -1) continue;
          dp[(i + 1) & 1][tmpj] =
              min(dp[(i + 1) & 1][tmpj],
                  dp[i & 1][j] + (r - l) * 2 - (maxl - minl));
        }
      }
    }
  }
  int ans = 40000;
  for (int ji = 0; ji < tot; ji++) {
    int j = dpi[ji];
    if (dp[n & 1][j] == inf) continue;
    ans = min(ans, dp[n & 1][j] + suan(j, a[n]));
  }
  cout << ans + 2 * n << endl;
  return 0;
}
