#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
inline void cmin(int &x, int y) {
  if (y < x) x = y;
}
inline void cmax(int &x, int y) {
  if (y > x) x = y;
}
using namespace std;
const int N = 2010;
bool vis[N][10][10000];
int a[N], b[N], n;
struct State {
  int i, j, st, d;
  State(int _i, int _j, int _st, int _d) : i(_i), j(_j), st(_st), d(_d) {}
};
queue<State> q;
void pushstate(int p, int j, int st, int d) {
  int x[4] = {0}, c = 0;
  for (int i = 0; i <= 3; i++) {
    x[c++] = st % 10, st /= 10;
    if (x[c - 1] == j || !x[c - 1]) x[--c] = 0;
  }
  while (c < 4 && p < n && a[p + 1] == j) ++p, x[c++] = b[p];
  sort(x, x + 4);
  st = 0;
  for (int i = 3; i >= 0; i--) st = st * 10 + x[i];
  if (!vis[p][j][st]) vis[p][j][st] = true, q.emplace(p, j, st, d);
}
void BFS() {
  pushstate(0, 1, 0, 2 * n);
  while (!q.empty()) {
    State o = q.front();
    q.pop();
    if (o.i == n && !o.st) {
      printf("%d\n", o.d);
      return;
    }
    for (int j : {o.j - 1, o.j + 1}) {
      if (j < 1 || j > 9) continue;
      pushstate(o.i, j, o.st, o.d + 1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
  BFS();
  return 0;
}
