#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int dp[10][10][10][10][2005];
bool check(int from, int to, int x) {
  if (from <= to) {
    if (from <= x && x <= to)
      return true;
    else
      return false;
  } else {
    if (to <= x && x <= from)
      return true;
    else
      return false;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int tn = 0; tn <= n; tn++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 10; l++) {
            dp[i][j][k][l][tn] = inf;
          }
        }
      }
    }
  }
  dp[0][0][0][0][0] = 0;
  int last = 1, now, a, b;
  for (int tn = 1; tn <= n; tn++) {
    scanf("%d%d", &a, &b);
    now = a;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 10; l++) {
            if (dp[i][j][k][l][tn - 1] < inf) {
              int tmp = dp[i][j][k][l][tn - 1];
              if (i) {
                int ti = b, tj = j, tk = k, tl = l;
                int has = 1;
                if (j && (check(last, i, j) || check(i, now, j))) tj = 0, has++;
                if (k && (check(last, i, k) || check(i, now, k))) tk = 0, has++;
                if (l && (check(last, i, l) || check(i, now, l))) tl = 0, has++;
                int cost = abs(i - last) + has + abs(now - i) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              } else {
                int ti = b, tj = j, tk = k, tl = l;
                int has = 0;
                if (j && check(last, now, j)) tj = 0, has++;
                if (k && check(last, now, k)) tk = 0, has++;
                if (l && check(last, now, l)) tl = 0, has++;
                int cost = has + abs(now - last) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              }
              if (j) {
                int ti = i, tj = b, tk = k, tl = l;
                int has = 1;
                if (i && (check(last, j, i) || check(j, now, i))) ti = 0, has++;
                if (k && (check(last, j, k) || check(j, now, k))) tk = 0, has++;
                if (l && (check(last, j, l) || check(j, now, l))) tl = 0, has++;
                int cost = abs(j - last) + has + abs(now - j) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              } else {
                int ti = i, tj = b, tk = k, tl = l;
                int has = 0;
                if (i && check(last, now, i)) ti = 0, has++;
                if (k && check(last, now, k)) tk = 0, has++;
                if (l && check(last, now, l)) tl = 0, has++;
                int cost = has + abs(now - last) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              }
              if (k) {
                int ti = i, tj = j, tk = b, tl = l;
                int has = 1;
                if (j && (check(last, k, j) || check(k, now, j))) tj = 0, has++;
                if (i && (check(last, k, i) || check(k, now, i))) ti = 0, has++;
                if (l && (check(last, k, l) || check(k, now, l))) tl = 0, has++;
                int cost = abs(k - last) + has + abs(now - k) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              } else {
                int ti = i, tj = j, tk = b, tl = l;
                int has = 0;
                if (j && check(last, now, j)) tj = 0, has++;
                if (i && check(last, now, i)) ti = 0, has++;
                if (l && check(last, now, l)) tl = 0, has++;
                int cost = has + abs(now - last) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              }
              if (l) {
                int ti = i, tj = j, tk = k, tl = b;
                int has = 1;
                if (j && (check(last, l, j) || check(l, now, j))) tj = 0, has++;
                if (k && (check(last, l, k) || check(l, now, k))) tk = 0, has++;
                if (i && (check(last, l, i) || check(l, now, i))) ti = 0, has++;
                int cost = abs(l - last) + has + abs(now - l) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              } else {
                int ti = i, tj = j, tk = k, tl = b;
                int has = 0;
                if (j && check(last, now, j)) tj = 0, has++;
                if (k && check(last, now, k)) tk = 0, has++;
                if (i && check(last, now, i)) ti = 0, has++;
                int cost = has + abs(now - last) + 1;
                dp[ti][tj][tk][tl][tn] =
                    min(dp[ti][tj][tk][tl][tn], tmp + cost);
              }
            }
          }
        }
      }
    }
    last = now;
  }
  int ans = inf;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        for (int l = 0; l < 10; l++) {
          if (dp[i][j][k][l][n] < inf) {
            int hig = -inf, low = inf;
            int have = 0;
            if (i > 0) {
              if (i >= now)
                hig = max(hig, i);
              else
                low = min(low, i);
              have++;
            }
            if (j > 0) {
              if (j >= now)
                hig = max(hig, j);
              else
                low = min(low, j);
              have++;
            }
            if (k > 0) {
              if (k >= now)
                hig = max(hig, k);
              else
                low = min(low, k);
              have++;
            }
            if (l > 0) {
              if (l >= now)
                hig = max(hig, l);
              else
                low = min(low, l);
              have++;
            }
            if (have == 0) {
              ans = min(ans, dp[i][j][k][l][n]);
            } else {
              if (hig > -inf && low < inf) {
                int cot =
                    min(hig - now + hig - low, now - low + hig - low) + have;
                ans = min(ans, dp[i][j][k][l][n] + cot);
              } else if (hig > -inf) {
                ans = min(ans, dp[i][j][k][l][n] + hig - now + have);
              } else if (low < inf) {
                ans = min(ans, dp[i][j][k][l][n] + now - low + have);
              }
            }
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
