#include <bits/stdc++.h>
using namespace std;
int n;
int people[2010], want[2010];
int dp[2010][12][12][12][12];
int dis(int a, int b) { return abs(a - b); }
int dfs(int k, int level, int a, int b, int c) {
  if (~dp[k][level][a][b][c]) return dp[k][level][a][b][c];
  int ret = 1000000;
  if (k > n) {
    if (a == 0 && b == 0 && c == 0) return 0;
    if (a) ret = min(ret, dfs(k, a, 0, b, c) + dis(level, a) + 1);
    if (b) ret = min(ret, dfs(k, b, a, 0, c) + dis(level, b) + 1);
    if (c) ret = min(ret, dfs(k, c, a, b, 0) + dis(level, c) + 1);
    return dp[k][level][a][b][c] = ret;
  }
  if (a) ret = min(ret, dfs(k, a, 0, b, c) + dis(level, a) + 1);
  if (b) ret = min(ret, dfs(k, b, a, 0, c) + dis(level, b) + 1);
  if (c) ret = min(ret, dfs(k, c, a, b, 0) + dis(level, c) + 1);
  if (a && b && c) {
    ret = min(ret, dfs(k + 1, want[k], a, b, c) + dis(level, people[k]) +
                       dis(people[k], want[k]) + 2);
    ret = min(ret, dfs(k + 1, a, want[k], b, c) + dis(level, people[k]) +
                       dis(people[k], a) + 2);
    ret = min(ret, dfs(k + 1, b, a, want[k], c) + dis(level, people[k]) +
                       dis(people[k], b) + 2);
    ret = min(ret, dfs(k + 1, c, a, b, want[k]) + dis(level, people[k]) +
                       dis(people[k], c) + 2);
  } else {
    if (!a)
      ret = min(ret, dfs(k + 1, people[k], want[k], b, c) +
                         dis(level, people[k]) + 1);
    else if (!b)
      ret = min(ret, dfs(k + 1, people[k], a, want[k], c) +
                         dis(level, people[k]) + 1);
    else
      ret = min(ret, dfs(k + 1, people[k], a, b, want[k]) +
                         dis(level, people[k]) + 1);
  }
  return dp[k][level][a][b][c] = ret;
}
int main() {
  scanf("%d", &n);
  memset(dp, 0xff, sizeof(dp));
  for (int i = 1; i <= n; i++) scanf("%d %d", &people[i], &want[i]);
  printf("%d\n", dfs(1, 1, 0, 0, 0));
  return 0;
}
