#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
map<string, int> dp[2005][10];
int st[2005], d[2005];
int n;
int DP(int i, int j, string s) {
  int pos, temp;
  if (dp[i][j].count(s)) return dp[i][j][s];
  dp[i][j][s] = INF;
  string rec = s;
  for (int k = 0; k < 4; k++) {
    temp = s[k] - '0';
    if (temp == j) s[k] = '0';
  }
  pos = i + 1;
  for (int k = 0; k < 4; k++) {
    temp = s[k] - '0';
    if (pos <= n && temp == 0 && st[pos] == j) s[k] = d[pos++] + '0';
  }
  if (i == n && s == "0000") return dp[i][j][rec] = 0;
  sort(s.begin(), s.end());
  for (int k = 3; k >= 0; k--) {
    if (s[k] - '0' != 0)
      dp[i][j][rec] = min(dp[i][j][rec],
                          DP(pos - 1, s[k] - '0', s) + abs((s[k] - '0') - j));
    else if (pos - 1 < n) {
      dp[i][j][rec] =
          min(dp[i][j][rec], DP(pos - 1, st[pos], s) + abs(st[pos] - j));
      break;
    }
  }
  return dp[i][j][rec];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %d", &st[i], &d[i]);
  printf("%d\n", DP(0, 1, "0000") + n * 2);
  return 0;
}
