#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MAXM = 720;
int n, X[MAXN], Y[MAXN];
int Index, id[10005], iid[MAXM], f[MAXN][10][MAXM];
bool vis[MAXN][10][MAXM];
inline int ID(int a, int b, int c, int d) {
  return a * 1000 + b * 100 + c * 10 + d;
}
inline int dp(int k, int pos, int sta) {
  if (k == n && iid[sta] == 0) return 0;
  if (vis[k][pos][sta]) return f[k][pos][sta];
  vis[k][pos][sta] = 1;
  int &ans = f[k][pos][sta];
  int x = iid[sta], a, b, c, d;
  d = x % 10;
  x /= 10;
  c = x % 10;
  x /= 10;
  b = x % 10;
  x /= 10;
  a = x % 10;
  x /= 10;
  if (a) ans = min(ans, dp(k, a, id[ID(0, b, c, d)]) + abs(pos - a));
  if (b) ans = min(ans, dp(k, b, id[ID(a, 0, c, d)]) + abs(pos - b));
  if (c) ans = min(ans, dp(k, c, id[ID(a, b, 0, d)]) + abs(pos - c));
  if (d) ans = min(ans, dp(k, d, id[ID(a, b, c, 0)]) + abs(pos - d));
  if (k < n && a == 0)
    ans = min(ans, dp(k + 1, X[k + 1], id[ID(Y[k + 1], b, c, d)]) +
                       abs(pos - X[k + 1]));
  return ans;
}
int main() {
  int tmp[5];
  for (int a = 0; a < 10; ++a)
    for (int b = a; b < 10; ++b)
      for (int c = b; c < 10; ++c)
        for (int d = c; d < 10; ++d) {
          int u = ID(a, b, c, d);
          id[u] = ++Index;
          iid[Index] = u;
        }
  for (int a = 0; a < 10; ++a)
    for (int b = 0; b < 10; ++b)
      for (int c = 0; c < 10; ++c)
        for (int d = 0; d < 10; ++d) {
          int u = ID(a, b, c, d);
          if (id[u]) continue;
          tmp[1] = a;
          tmp[2] = b;
          tmp[3] = c;
          tmp[4] = d;
          sort(tmp + 1, tmp + 5);
          id[u] = id[ID(tmp[1], tmp[2], tmp[3], tmp[4])];
        }
  scanf("%d", &n);
  memset(f, 0x3f, sizeof f);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &X[i], &Y[i]);
  printf("%d\n", dp(0, 1, id[0]) + (n << 1));
  return 0;
}
