#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x(0);
  char ch('@');
  bool flag(false);
  for (; !isdigit(ch); ch = getchar()) flag |= (ch == '-');
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return flag ? -x : x;
}
const int maxn = 2010;
int n;
int pos[maxn], tar[maxn];
int f[10][10][10][10][maxn];
inline int min(int a, int b) { return a < b ? a : b; }
inline int abs(int x) { return x > 0 ? x : -x; }
int dfs(int alr, int now, int a, int b, int c, int ans = 0x3f3f3f3f) {
  if (f[now][a][b][c][alr] != -1) return f[now][a][b][c][alr];
  if (alr > n) {
    if (!(a || b || c)) return f[now][a][b][c][alr] = 0;
    if (a) ans = min(ans, dfs(alr, a, 0, b, c) + abs(now - a) + 1);
    if (b) ans = min(ans, dfs(alr, b, a, 0, c) + abs(now - b) + 1);
    if (c) ans = min(ans, dfs(alr, c, a, b, 0) + abs(now - c) + 1);
    return f[now][a][b][c][alr] = ans;
  }
  if (a) ans = min(ans, dfs(alr, a, 0, b, c) + abs(now - a) + 1);
  if (b) ans = min(ans, dfs(alr, b, a, 0, c) + abs(now - b) + 1);
  if (c) ans = min(ans, dfs(alr, c, a, b, 0) + abs(now - c) + 1);
  if (a && b && c) {
    ans = min(ans, dfs(alr + 1, tar[alr], a, b, c) + abs(now - pos[alr]) +
                       abs(pos[alr] - tar[alr]) + 2);
    ans = min(ans, dfs(alr + 1, a, tar[alr], b, c) + abs(now - pos[alr]) +
                       abs(pos[alr] - a) + 2);
    ans = min(ans, dfs(alr + 1, b, a, tar[alr], c) + abs(now - pos[alr]) +
                       abs(pos[alr] - b) + 2);
    ans = min(ans, dfs(alr + 1, c, a, b, tar[alr]) + abs(now - pos[alr]) +
                       abs(pos[alr] - c) + 2);
  } else {
    if (a)
      ans = min(ans, dfs(alr, a, 0, b, c) + abs(now - a) + 1);
    else
      ans = min(ans, dfs(alr + 1, pos[alr], tar[alr], b, c) +
                         abs(now - pos[alr]) + 1);
    if (b)
      ans = min(ans, dfs(alr, b, a, 0, c) + abs(now - b) + 1);
    else
      ans = min(ans, dfs(alr + 1, pos[alr], a, tar[alr], c) +
                         abs(now - pos[alr]) + 1);
    if (c)
      ans = min(ans, dfs(alr, c, a, b, 0) + abs(now - c) + 1);
    else
      ans = min(ans, dfs(alr + 1, pos[alr], a, b, tar[alr]) +
                         abs(now - pos[alr]) + 1);
  }
  return f[now][a][b][c][alr] = ans;
}
int main() {
  n = read(), memset(f, -1, sizeof f);
  for (register int i(1); i <= n; ++i) pos[i] = read(), tar[i] = read();
  printf("%d\n", dfs(1, 1, 0, 0, 0));
  return 0;
}
