#include <bits/stdc++.h>
using namespace std;
long long N, s[2005], e[2005], DP[2][10][10][10][10][10], ans;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> s[i] >> e[i];
  for (int i = N; i >= 0; i--) {
    for (int a = 0; a <= 9; a++) {
      for (int b = 0; b <= 9; b++) {
        for (int c = 0; c <= 9; c++) {
          for (int d = 0; d <= 9; d++) {
            for (int f = 1; f <= 9; f++) {
              if (i == N && a == 0 && b == 0 && c == 0 && d == 0) continue;
              ans = (1LL << 60LL);
              if (i < N) {
                if (a == 0)
                  ans = min(ans, DP[(i + 1) % 2][s[i]][e[i]][b][c][d] +
                                     abs(f - s[i]));
                else if (b == 0)
                  ans = min(ans, DP[(i + 1) % 2][s[i]][a][e[i]][c][d] +
                                     abs(f - s[i]));
                else if (c == 0)
                  ans = min(ans, DP[(i + 1) % 2][s[i]][a][b][e[i]][d] +
                                     abs(f - s[i]));
                else if (d == 0)
                  ans = min(ans, DP[(i + 1) % 2][s[i]][a][b][c][e[i]] +
                                     abs(f - s[i]));
              }
              if (a != 0) ans = min(ans, DP[i % 2][a][0][b][c][d] + abs(f - a));
              if (b != 0) ans = min(ans, DP[i % 2][b][a][0][c][d] + abs(f - b));
              if (c != 0) ans = min(ans, DP[i % 2][c][a][b][0][d] + abs(f - c));
              if (d != 0) ans = min(ans, DP[i % 2][d][a][b][c][0] + abs(f - d));
              DP[i % 2][f][a][b][c][d] = ans;
            }
          }
        }
      }
    }
  }
  cout << DP[0][1][0][0][0][0] + 2 * N << "\n";
  return 0;
}
