#include <bits/stdc++.h>
using namespace std;
int n, a[2005], b[2005];
map<int, int> dp[2002][10];
int calc(int i, int now, int st) {
  if (i == n + 1 && st == 0) return 0;
  if (dp[i][now][st]) return dp[i][now][st];
  int t[4], d[4], tmp = st;
  for (int j = 3; j >= 0; j--) {
    t[j] = tmp % 10;
    tmp /= 10;
  }
  int res = 1e9;
  for (int j = 0; j <= 3; j++) {
    if (t[j] == 0) continue;
    for (int k = 0; k <= 3; k++) d[k] = t[k];
    d[j] = 0;
    sort(d, d + 4);
    int n_st = 0;
    for (int k = 0; k <= 3; k++) n_st = n_st * 10 + d[k];
    res = min(res, calc(i, t[j], n_st) + abs(now - t[j]));
  }
  if (t[0] == 0 && i <= n) {
    t[0] = b[i];
    sort(t, t + 4);
    int n_st = 0;
    for (int j = 0; j <= 3; j++) n_st = n_st * 10 + t[j];
    res = min(res, calc(i + 1, a[i], n_st) + abs(now - a[i]));
  }
  return dp[i][now][st] = res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  a[0] = 1;
  cout << calc(1, 1, 0) + 2 * n;
  return 0;
}
