#include <bits/stdc++.h>
using namespace std;
int n;
int dp[2010][10010];
int st[2010], ed[2010];
int pos[5], now;
void get_num(int x) {
  now = x % 10;
  pos[0] = x / 10 % 10;
  pos[1] = x / 100 % 10;
  pos[2] = x / 1000;
}
int get_sum() { return pos[2] * 1000 + pos[1] * 100 + pos[0] * 10 + now; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &st[i], &ed[i]);
  memset(dp, 0x3f3f3f3f, sizeof dp);
  dp[0][1] = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 9999; j > 0; j--) {
      if (dp[i][j] == 0x3f3f3f3f) continue;
      get_num(j);
      int now1 = now, p1;
      for (int k = 0; k < 3; k++)
        if (pos[k]) {
          now = pos[k];
          p1 = pos[k];
          pos[k] = 0;
          int nxt = get_sum();
          dp[i][nxt] = min(dp[i][nxt], dp[i][j] + abs(now1 - p1) + 1);
          get_num(j);
        }
      if (i == n) continue;
      for (int k = 0; k < 3; k++) {
        if (pos[k]) {
          now = pos[k];
          p1 = pos[k];
          pos[k] = ed[i + 1];
          int nxt = get_sum();
          dp[i + 1][nxt] =
              min(dp[i + 1][nxt], dp[i][j] + abs(now1 - st[i + 1]) + 1 +
                                      abs(st[i + 1] - now) + 1);
          get_num(j);
        } else {
          now = st[i + 1];
          p1 = pos[k];
          pos[k] = ed[i + 1];
          int nxt = get_sum();
          dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j] + abs(now1 - now) + 1);
          get_num(j);
        }
      }
      now = ed[i + 1];
      int nxt = get_sum();
      dp[i + 1][nxt] =
          min(dp[i + 1][nxt], dp[i][j] + abs(now1 - st[i + 1]) + 1 +
                                  abs(st[i + 1] - ed[i + 1]) + 1);
    }
  int res = 0x3FFFFFFF;
  for (int i = 1; i <= 9; i++) res = min(res, dp[n][i]);
  printf("%d", res);
}
