#include <bits/stdc++.h>
using namespace std;
int dp[2005][1505];
int positions[2005];
int destinations[2005];
int n;
vector<int> converttovector(int f) {
  vector<int> digits;
  while (f > 0) {
    digits.push_back(f % 10);
    f /= 10;
  }
  return digits;
}
int minpath1point(int low, int high, int point) {
  return min(abs(low - point), abs(high - point)) + high - low;
}
int vectortodecimal(vector<int> v, int sub) {
  vector<int> ans;
  for (vector<int>::iterator iter = v.begin(); iter != v.end(); iter++) {
    if (*iter != sub) {
      ans.push_back(*iter);
    }
  }
  int numans = 0;
  for (vector<int>::iterator iter = ans.begin(); iter != ans.end(); iter++) {
    numans *= 10;
    numans += *iter;
  }
  return numans;
}
int minpath2points(int end1, int end2, int point1, int point2) {
  return min(abs(end1 - point1) + abs(end2 - point2),
             abs(end1 - point2) + abs(end2 - point1)) +
         abs(end1 - end2);
}
int solve(int x, int y) {
  if (dp[x][y] != -1) {
    return dp[x][y];
  }
  vector<int> floors = converttovector(y);
  floors.push_back(destinations[x]);
  sort(floors.begin(), floors.end());
  int actualfloor = positions[x];
  if (x == n - 1) {
    dp[x][y] = minpath1point(floors[0], floors.back(), actualfloor);
    return dp[x][y];
  }
  int nextfloor = positions[x + 1];
  dp[x][y] = 1000000003;
  if (floors.size() < 4) {
    dp[x][y] = min(dp[x][y], solve(x + 1, vectortodecimal(floors, nextfloor)) +
                                 abs(actualfloor - nextfloor));
  }
  for (int i = 0; i < floors.size(); i++) {
    if (i > 0 && floors[i] == floors[i - 1]) {
    } else {
      for (int j = i; j < floors.size(); j++) {
        if (j + 1 >= n && floors[j] == floors[j + 1]) {
        } else {
          vector<int> newfloors;
          for (int k = 0; k < floors.size(); k++) {
            if (k < i || k > j) {
              newfloors.push_back(floors[k]);
            }
          }
          dp[x][y] =
              min(dp[x][y],
                  minpath2points(floors[i], floors[j], actualfloor, nextfloor) +
                      solve(x + 1, vectortodecimal(newfloors, nextfloor)));
        }
      }
    }
  }
  return dp[x][y];
}
int main() {
  cin >> n;
  for (int i = 0; i < 2005; i++) {
    for (int j = 0; j < 1505; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> positions[i] >> destinations[i];
  }
  cout << solve(0, 0) + positions[0] - 1 + 2 * n;
}
