#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e5 + 5;
int tu[10][10][10][10][10], tv[10][10][10][10][10];
int n, u[4], v[4], a, b, ans = INF;
void fill(int *u, int *v) {
  for (int i = 0; i < 4; ++i) u[i] = v[i];
}
void go(int f, int a, int b) {
  if (a != -1 and b != -1 and v[3] == 0) {
    fill(u, v);
    u[3] = b, sort(u, u + 4, greater<int>());
    int &x = tv[u[3]][u[2]][u[1]][u[0]][a];
    int y = tu[v[3]][v[2]][v[1]][v[0]][f];
    int dlt = abs(f - a) + 1;
    if (x == -1)
      x = y + dlt;
    else
      x = min(x, y + dlt);
  }
  for (int i = 0; i < 4; ++i)
    if (v[i]) {
      a = v[i];
      fill(u, v), u[i] = 0, sort(u, u + 4, greater<int>());
      int &x = tu[u[3]][u[2]][u[1]][u[0]][a];
      int y = tu[v[3]][v[2]][v[1]][v[0]][f];
      int dlt = abs(f - a) + 1;
      if (x == -1)
        x = y + dlt;
      else
        x = min(x, y + dlt);
    }
}
int main() {
  scanf("%d", &n);
  memset(tu, -1, sizeof tu);
  memset(tv, -1, sizeof tv);
  tu[0][0][0][0][1] = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a, &b);
    for (v[3] = 9; v[3] >= 0; --v[3])
      for (v[2] = 9; v[2] >= v[3]; --v[2])
        for (v[1] = 9; v[1] >= v[2]; --v[1])
          for (v[0] = 9; v[0] >= v[1]; --v[0])
            for (int f = 1; f <= 9; ++f)
              if (tu[v[3]][v[2]][v[1]][v[0]][f] != -1) go(f, a, b);
    swap(tu, tv);
    memset(tv, -1, sizeof tv);
  }
  for (int i = 0; i < 4; ++i)
    for (v[3] = 9; v[3] >= 0; --v[3])
      for (v[2] = 9; v[2] >= v[3]; --v[2])
        for (v[1] = 9; v[1] >= v[2]; --v[1])
          for (v[0] = 9; v[0] >= v[1]; --v[0])
            for (int f = 1; f <= 9; ++f)
              if (tu[v[3]][v[2]][v[1]][v[0]][f] != -1) go(f, -1, -1);
  for (int f = 1; f <= 9; ++f)
    if (tu[0][0][0][0][f] != -1) ans = min(ans, tu[0][0][0][0][f]);
  printf("%d\n", ans);
  return 0;
}
