#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int nxi() {
  int a;
  cin >> a;
  return a;
}
vector<int> a;
void inc(int i, int v) {
  for (; i < a.size(); i |= i + 1) {
    a[i] = max(a[i], v);
  }
}
int get(int r) {
  int ans = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    ans = max(ans, a[r]);
  }
  return ans;
}
int get(int l, int r) { return get(r) - get(l - 1); }
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
const int mod = 1000000007;
vector<int> p;
int dsuget(int v) { return (v == p[v]) ? v : (p[v] = dsuget(p[v])); }
void dsu_u(int a, int b) {
  a = dsuget(a);
  b = dsuget(b);
  if (rand() & 1) swap(a, b);
  if (a != b) p[a] = b;
}
int dyn[16][10][10][10][10][10];
int main() {
  int n = nxi();
  for (int i = 0; 4 * i < sizeof dyn; ++i) {
    *(((int*)dyn) + i) = INF;
  }
  vector<pair<int, int> > a(n);
  for (auto& p : a) cin >> p.first >> p.second;
  vector<int> tars1(4), tars2(4);
  dyn[0][0][0][0][0][1] = 0;
  for (int i = 0; i <= n; ++i) {
    int j = (i + 6) & 15;
    for (int t1 = 9; t1 >= 0; t1--) {
      for (int t2 = t1; t2 >= 0; t2--) {
        for (int t3 = t2; t3 >= 0; t3--) {
          for (int t4 = t3; t4 >= 0; t4--) {
            for (int f = 1; f <= 9; ++f) {
              dyn[j][t1][t2][t3][t4][f] = INF;
            }
          }
        }
      }
    }
    for (int t1 = 9; t1 >= 0; t1--) {
      for (int t2 = t1; t2 >= 0; t2--) {
        for (int t3 = t2; t3 >= 0; t3--) {
          for (int t4 = t3; t4 >= 0; t4--) {
            for (int f = 1; f <= 9; ++f) {
              if (dyn[i & 15][t1][t2][t3][t4][f] == INF) continue;
              tars1[0] = t1;
              tars1[1] = t2;
              tars1[2] = t3;
              tars1[3] = t4;
              for (int t = 0; t < 5; ++t) {
                if (t == 4 && i == n) break;
                int new_floor = t == 4 ? a[i].first : tars1[t];
                if (new_floor == 0) continue;
                int delta = abs(new_floor - f);
                copy(tars1.begin(), tars1.end(), tars2.begin());
                for (int& v : tars2) {
                  if (v == new_floor) {
                    delta++;
                    v = 0;
                  }
                }
                int j = i;
                while (j < n && a[j].first == new_floor) {
                  bool placed = false;
                  for (int& v : tars2)
                    if (v == 0) {
                      placed = true;
                      v = a[j].second;
                      break;
                    }
                  if (placed) {
                    delta++;
                    j++;
                  } else
                    break;
                }
                sort(tars2.begin(), tars2.end(), greater<int>());
                dyn[j & 15][tars2[0]][tars2[1]][tars2[2]][tars2[3]][new_floor] =
                    min(dyn[j & 15][tars2[0]][tars2[1]][tars2[2]][tars2[3]]
                           [new_floor],
                        dyn[i & 15][t1][t2][t3][t4][f] + delta);
              }
            }
          }
        }
      }
    }
  }
  int ans = INF;
  for (int f = 1; f <= 9; ++f) ans = min(ans, dyn[n & 15][0][0][0][0][f]);
  cout << ans;
  return 0;
}
