#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, a[N], b[N], dp[N][10][10][10][10];
int dfs(int p, int x1, int x2, int x3, int x4, int now) {
  if (p == n + 1 && !x4) return 0;
  if (x1 == 0 && dp[p][x2][x3][x4][now] >= 0) return dp[p][x2][x3][x4][now];
  int ret = 1 << 30;
  if (x1) ret = min(ret, dfs(p, 0, x2, x3, x4, x1) + abs(now - x1) + 1);
  if (x2) ret = min(ret, dfs(p, 0, x1, x3, x4, x2) + abs(now - x2) + 1);
  if (x3) ret = min(ret, dfs(p, 0, x1, x2, x4, x3) + abs(now - x3) + 1);
  if (x4) ret = min(ret, dfs(p, 0, x1, x2, x3, x4) + abs(now - x4) + 1);
  if (x1) return ret;
  if (p <= n) {
    int x[5] = {0, b[p], x2, x3, x4};
    sort(x + 1, x + 5);
    ret = min(ret,
              dfs(p + 1, x[1], x[2], x[3], x[4], a[p]) + abs(now - a[p]) + 1);
  }
  return dp[p][x2][x3][x4][now] = ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  cout << dfs(1, 0, 0, 0, 0, 1) << endl;
}
