#include <bits/stdc++.h>
using namespace std;
inline int encode(int *p) {
  int s = 0;
  for (int i = 0; i < 9; i++) s = s * 5 + p[i];
  return s;
}
inline void decode(int x, int *p) {
  for (int i = 8; i >= 0; i--) {
    p[i] = x % 5;
    x /= 5;
  }
}
int now[10], id[2000000], cnt;
void dfs(int d, int s) {
  if (d >= 9) {
    id[encode(now)] = ++cnt;
    return;
  }
  for (int i = 0; i <= 4 - s; i++) {
    now[d] = i;
    dfs(d + 1, s + i);
  }
}
int f[2005][800][10], a[2005], b[2005], n;
inline void update(int &x, int y) { x = min(x, y); }
int dp(int d, int st, int pos) {
  int now[10];
  if (d > n) return 0x3f3f3f3f;
  if (d >= n && !st) return 0;
  if (f[d][id[st]][pos] < 0x3f3f3f3f) return f[d][id[st]][pos];
  decode(st, now);
  int s = 0;
  for (int i = 0; i < 9; i++)
    if (now[i]) {
      int t = now[i];
      now[i] = 0;
      update(f[d][id[st]][pos], dp(d, encode(now), i) + abs(pos - i));
      s += t;
      now[i] = t;
    }
  if (s < 4) {
    now[a[d + 1]] = 0;
    now[b[d + 1]]++;
    update(f[d][id[st]][pos],
           dp(d + 1, encode(now), a[d + 1]) + abs(pos - a[d + 1]));
  }
  return f[d][id[st]][pos];
}
int main() {
  memset(f, 0x3f, sizeof(f));
  dfs(0, 0);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
  }
  printf("%d\n", dp(0, 0, 0) + 2 * n);
  return 0;
}
