#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MAXM = 11;
const int inf = 1e9 + 7;
int f[MAXM][MAXM][MAXM][MAXM][MAXN];
int from[MAXN], to[MAXN];
int k, n;
void init() {
  for (int i = 0; i < MAXM; ++i)
    for (int j = 0; j < MAXM; ++j)
      for (int x = 0; x < MAXM; ++x)
        for (int y = 0; y < MAXM; ++y)
          for (int z = 0; z < MAXN; ++z) f[i][j][x][y][z] = inf;
}
void sot(int &a, int &b, int &c) {
  if (a < b) swap(a, b);
  if (a < c) swap(a, c);
  if (b < c) swap(b, c);
}
int dfs(int num, int a, int b, int c, int index, int now) {
  sot(a, b, c);
  if (index > n && num == 0) return 0;
  if (f[now][a][b][c][index] != inf) return f[now][a][b][c][index];
  if (num == 0) {
    f[now][a][b][c][index] =
        min(dfs(num + 1, to[index], b, c, index + 1, from[index]) + 1 +
                abs(now - from[index]),
            f[now][a][b][c][index]);
  }
  if (num == 1) {
    if (index <= n) {
      f[now][a][b][c][index] =
          min(dfs(num + 1, a, to[index], c, index + 1, from[index]) + 1 +
                  abs(now - from[index]),
              f[now][a][b][c][index]);
    }
    f[now][a][b][c][index] =
        min(dfs(num - 1, 0, b, c, index, a) + 1 + abs(now - a),
            f[now][a][b][c][index]);
  }
  if (num == 2) {
    if (index <= n) {
      f[now][a][b][c][index] =
          min(dfs(num + 1, a, b, to[index], index + 1, from[index]) + 1 +
                  abs(now - from[index]),
              f[now][a][b][c][index]);
    }
    f[now][a][b][c][index] =
        min(dfs(num - 1, 0, b, c, index, a) + 1 + abs(now - a),
            f[now][a][b][c][index]);
    f[now][a][b][c][index] =
        min(dfs(num - 1, a, 0, c, index, b) + 1 + abs(now - b),
            f[now][a][b][c][index]);
  }
  if (num == 3) {
    f[now][a][b][c][index] =
        min(dfs(num - 1, 0, b, c, index, a) + abs(now - a) + 1,
            f[now][a][b][c][index]);
    f[now][a][b][c][index] =
        min(dfs(num - 1, a, 0, c, index, b) + abs(now - b) + 1,
            f[now][a][b][c][index]);
    f[now][a][b][c][index] =
        min(dfs(num - 1, a, b, 0, index, c) + abs(now - c) + 1,
            f[now][a][b][c][index]);
    if (index <= n) {
      f[now][a][b][c][index] =
          min(dfs(num, a, b, to[index], index + 1, from[index]) + abs(now - c) +
                  abs(c - from[index]) + 2,
              f[now][a][b][c][index]);
      f[now][a][b][c][index] =
          min(dfs(num, a, b, to[index], index + 1, c) + abs(now - from[index]) +
                  abs(from[index] - c) + 2,
              f[now][a][b][c][index]);
      f[now][a][b][c][index] =
          min(dfs(num, a, to[index], c, index + 1, from[index]) + abs(now - b) +
                  abs(b - from[index]) + 2,
              f[now][a][b][c][index]);
      f[now][a][b][c][index] =
          min(dfs(num, a, to[index], c, index + 1, b) + abs(now - from[index]) +
                  abs(from[index] - b) + 2,
              f[now][a][b][c][index]);
      f[now][a][b][c][index] =
          min(dfs(num, to[index], b, c, index + 1, from[index]) + abs(now - a) +
                  abs(a - from[index]) + 2,
              f[now][a][b][c][index]);
      f[now][a][b][c][index] =
          min(dfs(num, to[index], b, c, index + 1, a) + abs(now - from[index]) +
                  abs(from[index] - a) + 2,
              f[now][a][b][c][index]);
      f[now][a][b][c][index] =
          min(dfs(num, a, b, c, index + 1, to[index]) + abs(now - from[index]) +
                  abs(from[index] - to[index]) + 2,
              f[now][a][b][c][index]);
    }
  }
  return f[now][a][b][c][index];
}
int aa, bb, cc;
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &from[i], &to[i]);
  }
  printf("%d", dfs(0, 0, 0, 0, 1, 1));
}
