#include <bits/stdc++.h>
using namespace std;
const int INF = 900000000;
int now, pos[10], s[3000], t[3000], dp[2010][10010];
int getsum() {
  int ret;
  ret = pos[2] * 1000 + pos[1] * 100 + pos[0] * 10 + now;
  return ret;
}
void getnum(int x) {
  int top, i;
  now = x % 10;
  x = x / 10;
  top = 0;
  for (i = 0; i <= 4; i++) pos[i] = 0;
  while (x) {
    pos[top++] = x % 10;
    x /= 10;
  }
}
int main() {
  int n, i, j, now1, k, status, ans;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &s[i], &t[i]);
  }
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  dp[0][1] = 0;
  for (i = 0; i <= n; i++) {
    for (j = 9999; j > 0; j--) {
      if (dp[i][j] == 0x3f3f3f3f) continue;
      getnum(j);
      now1 = now;
      for (k = 0; k < 3; k++) {
        if (pos[k]) {
          now = pos[k];
          pos[k] = 0;
          status = getsum();
          dp[i][status] = min(dp[i][status], dp[i][j] + abs(now1 - now) + 1);
          getnum(j);
        }
      }
      if (i == n) continue;
      for (k = 0; k < 3; k++) {
        if (pos[k]) {
          now = pos[k];
          pos[k] = t[i + 1];
          status = getsum();
          dp[i + 1][status] =
              min(dp[i + 1][status], dp[i][j] + abs(now1 - s[i + 1]) + 1 +
                                         abs(s[i + 1] - now) + 1);
          getnum(j);
        } else {
          now = s[i + 1];
          pos[k] = t[i + 1];
          status = getsum();
          dp[i + 1][status] =
              min(dp[i + 1][status], dp[i][j] + abs(now1 - s[i + 1]) + 1);
          getnum(j);
        }
      }
      now = t[i + 1];
      status = getsum();
      dp[i + 1][status] =
          min(dp[i + 1][status],
              dp[i][j] + abs(now1 - s[i + 1]) + 1 + abs(now - s[i + 1]) + 1);
    }
  }
  ans = INF;
  for (i = 1; i <= 9; i++) {
    ans = min(ans, dp[n][i]);
  }
  printf("%d\n", ans);
  return 0;
}
