#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> states;
int dp[2][10][10][10][10][10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 1; i <= 9; i++) dp[n & 1][i][0][0][0][0] = 0;
  for (int i = n; i >= 0; i--) {
    for (int p1 = 0; p1 <= 9; p1++) {
      for (int p2 = p1; p2 <= 9; p2++) {
        for (int p3 = p2; p3 <= 9; p3++) {
          for (int p4 = p3; p4 <= 9; p4++) {
            for (int now = 1; now <= 9; now++) {
              int cans = 1e9;
              if (i < n && (!p1 || !p2 || !p3 || !p4)) {
                vector<int> p = {p1, p2, p3, p4, a[i].second};
                sort(p.begin(), p.end());
                cans = min(
                    cans,
                    abs(now - a[i].first) +
                        dp[(i + 1) & 1][a[i].first][p[1]][p[2]][p[3]][p[4]]);
              }
              if (p1 != 0) {
                cans = min(cans, abs(now - p1) + dp[i & 1][p1][0][p2][p3][p4]);
              }
              if (p2 != 0) {
                cans = min(cans, abs(now - p2) + dp[i & 1][p2][0][p1][p3][p4]);
              }
              if (p3 != 0) {
                cans = min(cans, abs(now - p3) + dp[i & 1][p3][0][p1][p2][p4]);
              }
              if (p4 != 0) {
                cans = min(cans, abs(now - p4) + dp[i & 1][p4][0][p1][p2][p3]);
              }
              dp[i & 1][now][p1][p2][p3][p4] =
                  min(dp[i & 1][now][p1][p2][p3][p4], cans);
            }
          }
        }
      }
    }
    memset(dp[(i + 1) & 1], 0x3f, sizeof(dp[(i + 1) & 1]));
  }
  cout << dp[0][1][0][0][0][0] + 2 * n << endl;
  return 0;
}
