#include <bits/stdc++.h>
using namespace std;
const int LN = 2e3 + 5, LM = 1200, INF = 1e9;
int N, start[LN], dest[LN], dp[LN][10][10][10][10];
vector<int> temp;
void save(int pers, int floor, int pa, int pb, int pc, int res) {
  temp = {pa, pb, pc};
  do {
    dp[pers][floor][temp[0]][temp[1]][temp[2]] = res;
  } while (next_permutation((temp).begin(), (temp).end()));
  return;
}
int solve(int pers, int floor, int pa, int pb, int pc) {
  if (dp[pers][floor][pa][pb][pc] != -1) return dp[pers][floor][pa][pb][pc];
  int res = INF;
  if (pers == N) {
    if (!pa && !pb && !pc) return 0;
    if (pa) res = min(res, solve(pers, pa, 0, pb, pc) + abs(pa - floor) + 1);
    if (pb) res = min(res, solve(pers, pb, pa, 0, pc) + abs(pb - floor) + 1);
    if (pc) res = min(res, solve(pers, pc, pa, pb, 0) + abs(pc - floor) + 1);
    save(pers, floor, pa, pb, pc, res);
    return res;
  }
  if (pa) res = min(res, solve(pers, pa, 0, pb, pc) + abs(pa - floor) + 1);
  if (pb) res = min(res, solve(pers, pb, pa, 0, pc) + abs(pb - floor) + 1);
  if (pc) res = min(res, solve(pers, pc, pa, pb, 0) + abs(pc - floor) + 1);
  if (pa && pb && pc) {
    res = min(res, solve(pers + 1, dest[pers], pa, pb, pc) +
                       abs(start[pers] - floor) +
                       abs(dest[pers] - start[pers]) + 2);
    res = min(res, solve(pers + 1, pa, dest[pers], pb, pc) +
                       abs(start[pers] - floor) + abs(start[pers] - pa) + 2);
    res = min(res, solve(pers + 1, pb, pa, dest[pers], pc) +
                       abs(start[pers] - floor) + abs(start[pers] - pb) + 2);
    res = min(res, solve(pers + 1, pc, pa, pb, dest[pers]) +
                       abs(start[pers] - floor) + abs(start[pers] - pc) + 2);
  } else {
    if (!pa)
      res = min(res, solve(pers + 1, start[pers], dest[pers], pb, pc) +
                         abs(start[pers] - floor) + 1);
    else if (!pb)
      res = min(res, solve(pers + 1, start[pers], pa, dest[pers], pc) +
                         abs(start[pers] - floor) + 1);
    else if (!pc)
      res = min(res, solve(pers + 1, start[pers], pa, pb, dest[pers]) +
                         abs(start[pers] - floor) + 1);
  }
  save(pers, floor, pa, pb, pc, res);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < N; i++) cin >> start[i] >> dest[i];
  cout << solve(0, 1, 0, 0, 0);
  return 0;
}
