#include <bits/stdc++.h>
void IO(bool inp, bool out) {
  if (inp) freopen("k.inp", "r", stdin);
  if (out) freopen("k.out", "w", stdout);
}
using namespace std;
short n, a[2002], b[2002];
int op[2002][10][10][10][10];
bool f[2002][10][10][10][10];
void MIN(int &u, int v) {
  if (v < u) u = v;
}
int dfs(short id, short t1, short t2, short t3, short t4, short vt) {
  if (id == n + 1 && !t4) return 0;
  if (!t1 && f[id][t2][t3][t4][vt]) return op[id][t2][t3][t4][vt];
  int kq = 100000;
  if (t1) MIN(kq, dfs(id, 0, t2, t3, t4, t1) + abs(t1 - vt) + 1);
  if (t2) MIN(kq, dfs(id, 0, t1, t3, t4, t2) + abs(t2 - vt) + 1);
  if (t3) MIN(kq, dfs(id, 0, t1, t2, t4, t3) + abs(t3 - vt) + 1);
  if (t4) MIN(kq, dfs(id, 0, t1, t2, t3, t4) + abs(t4 - vt) + 1);
  if (t1) return kq;
  if (id <= n) {
    short c[4] = {b[id], t2, t3, t4};
    sort(c, c + 4);
    MIN(kq, dfs(id + 1, c[0], c[1], c[2], c[3], a[id]) + abs(a[id] - vt) + 1);
  }
  f[id][t2][t3][t4][vt] = true;
  return op[id][t2][t3][t4][vt] = kq;
}
int main() {
  IO(0, 0);
  scanf("%hd", &n);
  for (short i = 1; i <= n; ++i) scanf("%hd%hd", &a[i], &b[i]);
  printf("%d", dfs(1, 0, 0, 0, 0, 1));
}
