#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 2000 + 11;
int N, a[maxn], b[maxn];
bool used[maxn][10][10][10][10][10];
queue<tuple<int, int, char, char, char, char, char> > Q;
void resort(char &f1, char &f2, char &f3, char &f4) {
  if (f1 > f2) swap(f1, f2);
  if (f2 > f3) swap(f2, f3);
  if (f3 > f4) swap(f3, f4);
  if (f1 > f2) swap(f1, f2);
  if (f2 > f3) swap(f2, f3);
  if (f1 > f2) swap(f1, f2);
}
void push_in(int n, int t, char floor, char f1, char f2, char f3, char f4) {
  if (used[n][floor][f1][f2][f3][f4]) return;
  used[n][floor][f1][f2][f3][f4] = 1;
  if (n == N && !f1 && !f2 && !f3 && !f4) throw t;
  Q.push(make_tuple(n, t, floor, f1, f2, f3, f4));
}
void bfs() {
  tuple<int, int, char, char, char, char, char> s =
      make_tuple(0, 0, 1, 0, 0, 0, 0);
  Q.push(s);
  int n, t;
  char floor, f1, f2, f3, f4;
  while (1) {
    tuple<int, int, char, char, char, char, char> cur = Q.front();
    Q.pop();
    tie(n, t, floor, f1, f2, f3, f4) = cur;
    resort(f1, f2, f3, f4);
    if (floor < 9) push_in(n, t + 1, floor + 1, f1, f2, f3, f4);
    if (floor > 0) push_in(n, t + 1, floor - 1, f1, f2, f3, f4);
    if (f1 == floor) push_in(n, t + 1, floor, 0, f2, f3, f4);
    if (f2 == floor) push_in(n, t + 1, floor, f1, 0, f3, f4);
    if (f3 == floor) push_in(n, t + 1, floor, f1, f2, 0, f4);
    if (f4 == floor) push_in(n, t + 1, floor, f1, f2, f3, 0);
    if (f1 == 0 && n < N && a[n + 1] == floor)
      push_in(n + 1, t + 1, floor, b[n + 1], f2, f3, f4);
  }
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) scanf("%d%d", &a[i], &b[i]);
  try {
    bfs();
  } catch (int &x) {
    cout << x << endl;
  }
  return 0;
}
