#include <bits/stdc++.h>
using namespace std;
int dp[2009][10][10][10];
int a[2009], b[2009], n;
int main() {
  scanf("%d", &n);
  for (int i = 1; (i) <= int(n); (i)++) scanf("%d %d", &a[i], &b[i]);
  for (int i = n; i >= 1; i--) {
    for (int a1 = 0; (a1) < int(10); (a1)++)
      for (int a2 = 0; (a2) < int(10); (a2)++)
        for (int a3 = 0; (a3) < int(10); (a3)++) {
          vector<int> path;
          path.push_back(a[i]);
          path.push_back(b[i]);
          if (a1 != 0) path.push_back(a1);
          if (a2 != 0) path.push_back(a2);
          if (a3 != 0) path.push_back(a3);
          sort(path.begin() + 1, path.end());
          dp[i][a1][a2][a3] = 0x3f3f3f3f;
          do {
            int sum = 0;
            int left = path.size();
            int psz = path.size();
            for (int it = 0; (it) < int(psz); (it)++) {
              left--;
              if (i < n) {
                if (left <= 3) {
                  int cost = sum +
                             dp[i + 1][left > 0 ? path[psz - 1] : 0]
                               [left > 1 ? path[psz - 2] : 0]
                               [left > 2 ? path[psz - 3] : 0] +
                             abs(path[it] - a[i + 1]);
                  if (dp[i][a1][a2][a3] > cost) dp[i][a1][a2][a3] = cost;
                }
              } else {
                if (left == 0) {
                  int cost = sum;
                  if (dp[i][a1][a2][a3] > cost) dp[i][a1][a2][a3] = cost;
                }
              }
              if (left != 0) {
                sum += abs(path[it + 1] - path[it]);
              }
            }
          } while (next_permutation(path.begin() + 1, path.end()));
        }
  }
  printf("%d\n", dp[1][0][0][0] + 2 * n + abs(1 - a[1]));
  return 0;
}
