#include <bits/stdc++.h>
using namespace std;
int n, u[2007], v[2007], f[2007][11][11][11][11];
int dist(int a, int b) { return abs(a - b); }
int dfs(int i, int cur, int a, int b, int c) {
  if (~f[i][cur][a][b][c]) return f[i][cur][a][b][c];
  int r = 0x3f3f3f3f;
  if (i > n) {
    if (!a && !b && !c) return 0;
    if (a) r = min(r, dfs(i, a, 0, b, c) + abs(cur - a) + 1);
    if (b) r = min(r, dfs(i, b, a, 0, c) + abs(cur - b) + 1);
    if (c) r = min(r, dfs(i, c, a, b, 0) + abs(cur - c) + 1);
    return f[i][cur][a][b][c] = r;
  }
  if (a) r = min(r, dfs(i, a, 0, b, c) + abs(cur - a) + 1);
  if (b) r = min(r, dfs(i, b, a, 0, c) + abs(cur - b) + 1);
  if (c) r = min(r, dfs(i, c, a, b, 0) + abs(cur - c) + 1);
  if (a && b && c) {
    r = min(r,
            dfs(i + 1, v[i], a, b, c) + abs(cur - u[i]) + abs(u[i] - v[i]) + 2);
    r = min(r, dfs(i + 1, a, v[i], b, c) + abs(cur - u[i]) + abs(u[i] - a) + 2);
    r = min(r, dfs(i + 1, b, a, v[i], c) + abs(cur - u[i]) + abs(u[i] - b) + 2);
    r = min(r, dfs(i + 1, c, a, b, v[i]) + abs(cur - u[i]) + abs(u[i] - c) + 2);
  } else {
    if (!a)
      r = min(r, dfs(i + 1, u[i], v[i], b, c) + abs(cur - u[i]) + 1);
    else if (!b)
      r = min(r, dfs(i + 1, u[i], a, v[i], c) + abs(cur - u[i]) + 1);
    else
      r = min(r, dfs(i + 1, u[i], a, b, v[i]) + abs(cur - u[i]) + 1);
  }
  return f[i][cur][a][b][c] = r;
}
int main() {
  memset(f, 0xff, sizeof(f));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &u[i], &v[i]);
  printf("%d\n", dfs(1, 1, 0, 0, 0));
  return 0;
}
