#include <bits/stdc++.h>
using namespace std;
int n;
int from[2010], to[2010];
int f[2010][10][10][10][10];
int dis(int a, int b) { return abs(a - b); }
int dfs(int k, int num, int a, int b, int c) {
  if (f[k][num][a][b][c] != f[0][0][0][0][0]) return f[k][num][a][b][c];
  int ans = f[0][0][0][0][0];
  if (k > n) {
    if (a == 0 && b == 0 && c == 0) return 0;
    if (a) {
      ans = min(ans, dfs(k, a, 0, b, c) + dis(num, a) + 1);
    }
    if (b) {
      ans = min(ans, dfs(k, b, a, 0, c) + dis(num, b) + 1);
    }
    if (c) {
      ans = min(ans, dfs(k, c, a, b, 0) + dis(num, c) + 1);
    }
    f[k][num][a][b][c] = ans;
    return ans;
  }
  if (a) {
    ans = min(ans, dfs(k, a, 0, b, c) + dis(num, a) + 1);
  }
  if (b) {
    ans = min(ans, dfs(k, b, a, 0, c) + dis(num, b) + 1);
  }
  if (c) {
    ans = min(ans, dfs(k, c, a, b, 0) + dis(num, c) + 1);
  }
  if (!a) {
    ans = min(ans, dfs(k + 1, from[k], to[k], b, c) + dis(num, from[k]) + 1);
  } else if (!b) {
    ans = min(ans, dfs(k + 1, from[k], a, to[k], c) + dis(num, from[k]) + 1);
  } else if (!c) {
    ans = min(ans, dfs(k + 1, from[k], a, b, to[k]) + dis(num, from[k]) + 1);
  }
  ans = min(ans, dfs(k + 1, to[k], a, b, c) + dis(num, from[k]) +
                     dis(from[k], to[k]) + 2);
  ans = min(ans, dfs(k + 1, a, to[k], b, c) + dis(num, from[k]) +
                     dis(from[k], a) + 2);
  ans = min(ans, dfs(k + 1, b, a, to[k], c) + dis(num, from[k]) +
                     dis(from[k], b) + 2);
  ans = min(ans, dfs(k + 1, c, a, b, to[k]) + dis(num, from[k]) +
                     dis(from[k], c) + 2);
  f[k][num][a][b][c] = ans;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &from[i], &to[i]);
  }
  memset(f, 0x3f3f3f3f, sizeof(f));
  cout << dfs(1, 1, 0, 0, 0) << endl;
  return 0;
}
