#include <bits/stdc++.h>
using namespace std;
int n, sta[2005], arr[2005];
int f[2005][10][10][10][10];
int dfs(int i, int flo, int a, int b, int c) {
  if (f[i][flo][a][b][c]) return f[i][flo][a][b][c];
  int step = 0x3f3f3f3f;
  if (i > n) {
    if (a + b + c == 0) return 0;
    if (a) step = min(step, dfs(i, a, 0, b, c) + abs(flo - a) + 1);
    if (b) step = min(step, dfs(i, b, a, 0, c) + abs(flo - b) + 1);
    if (c) step = min(step, dfs(i, c, a, b, 0) + abs(flo - c) + 1);
    f[i][flo][a][b][c] = step;
    return step;
  }
  if (a) step = min(step, dfs(i, a, 0, b, c) + abs(flo - a) + 1);
  if (b) step = min(step, dfs(i, b, a, 0, c) + abs(flo - b) + 1);
  if (c) step = min(step, dfs(i, c, a, b, 0) + abs(flo - c) + 1);
  if (a * b * c) {
    step = min(step, dfs(i + 1, arr[i], a, b, c) + abs(flo - sta[i]) +
                         abs(sta[i] - arr[i]) + 2);
    step = min(step, dfs(i + 1, a, arr[i], b, c) + abs(flo - sta[i]) +
                         abs(sta[i] - a) + 2);
    step = min(step, dfs(i + 1, b, a, arr[i], c) + abs(flo - sta[i]) +
                         abs(sta[i] - b) + 2);
    step = min(step, dfs(i + 1, c, a, b, arr[i]) + abs(flo - sta[i]) +
                         abs(sta[i] - c) + 2);
  } else {
    if (!a)
      step =
          min(step, dfs(i + 1, sta[i], arr[i], b, c) + abs(flo - sta[i]) + 1);
    if (!b)
      step =
          min(step, dfs(i + 1, sta[i], a, arr[i], c) + abs(flo - sta[i]) + 1);
    if (!c)
      step =
          min(step, dfs(i + 1, sta[i], a, b, arr[i]) + abs(flo - sta[i]) + 1);
  }
  f[i][flo][a][b][c] = step;
  return step;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &sta[i], &arr[i]);
  }
  printf("%d", dfs(1, 1, 0, 0, 0));
  return 0;
}
