#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
long long qp(long long base, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * base) % mod;
    base = (base * base) % mod;
    n >>= 1;
  }
  return res;
}
int n, q;
int from[maxn], to[maxn], f[maxn][11][11][11][11];
int dis(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] != -1) return f[i][cur][a][b][c];
  int ret = inf;
  if (i > n) {
    if (a == 0 && b == 0 && c == 0) return 0;
    if (a) ret = min(ret, dfs(i, a, 0, b, c) + dis(cur, a) + 1);
    if (b) ret = min(ret, dfs(i, b, a, 0, c) + dis(cur, b) + 1);
    if (c) ret = min(ret, dfs(i, c, a, b, 0) + dis(cur, c) + 1);
    return f[i][cur][a][b][c] = ret;
  }
  if (a) ret = min(ret, dfs(i, a, 0, b, c) + dis(cur, a) + 1);
  if (b) ret = min(ret, dfs(i, b, a, 0, c) + dis(cur, b) + 1);
  if (c) ret = min(ret, dfs(i, c, a, b, 0) + dis(cur, c) + 1);
  if (a && b && c) {
    ret = min(ret, dfs(i + 1, to[i], a, b, c) + dis(cur, from[i]) + 1 +
                       dis(from[i], to[i]) + 1);
    ret = min(ret, dfs(i + 1, a, to[i], b, c) + dis(cur, from[i]) + 1 +
                       dis(from[i], a) + 1);
    ret = min(ret, dfs(i + 1, b, a, to[i], c) + dis(cur, from[i]) + 1 +
                       dis(from[i], b) + 1);
    ret = min(ret, dfs(i + 1, c, a, b, to[i]) + dis(cur, from[i]) + 1 +
                       dis(from[i], c) + 1);
  } else {
    if (!a)
      ret = min(ret, dfs(i + 1, from[i], to[i], b, c) + dis(cur, from[i]) + 1);
    else if (!b)
      ret = min(ret, dfs(i + 1, from[i], a, to[i], c) + dis(cur, from[i]) + 1);
    else if (!c)
      ret = min(ret, dfs(i + 1, from[i], a, b, to[i]) + dis(cur, from[i]) + 1);
  }
  return f[i][cur][a][b][c] = ret;
}
int main() {
  while (~scanf("%d", &n)) {
    memset(f, -1, sizeof(f));
    for (int i = 1; i <= n; i++) scanf("%d%d", &from[i], &to[i]);
    int ans = dfs(1, 1, 0, 0, 0);
    printf("%d\n", ans);
  }
  return 0;
}
