#include <bits/stdc++.h>
using namespace std;
map<tuple<int, int, int, long long>, int> D;
struct Cmp {
  bool operator()(const tuple<int, int, int, long long>& a,
                  const tuple<int, int, int, long long>& b) {
    return D[a] > D[b];
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int, int> > emp(n);
  for (int i = 0; i < n; i++) {
    cin >> emp[i].first >> emp[i].second;
  }
  priority_queue<tuple<int, int, int, long long>,
                 vector<tuple<int, int, int, long long> >, Cmp>
      Q;
  tuple<int, int, int, long long> initial = make_tuple(0, 1, 0, 0);
  Q.push(initial);
  D[initial] = 0;
  int ret = 1e9;
  while (!Q.empty()) {
    tuple<int, int, int, long long> v = Q.top();
    Q.pop();
    if (get<0>(v) == n and get<2>(v) == 0) {
      ret = min(ret, D[v]);
      continue;
    }
    long long eee = (get<3>(v) >> (get<1>(v) * 3)) & 7LL;
    if (eee > 0) {
      eee = 1;
      auto w = v;
      get<2>(w) -= eee;
      get<3>(w) -= (eee << (get<1>(v) * 3));
      if (D.find(w) == D.end()) {
        D[w] = D[v] + eee;
        Q.push(w);
      }
      continue;
    }
    for (int d = -1; d <= 1; d += 2) {
      tuple<int, int, int, long long> w = v;
      get<1>(w) += d;
      if (not(1 <= get<1>(w) and get<1>(w) <= 9)) continue;
      if (D.find(w) == D.end()) {
        D[w] = D[v] + 1;
        Q.push(w);
      }
    }
    if (get<0>(v) < n and emp[get<0>(v)].first == get<1>(v) and get<2>(v) < 4) {
      auto w = v;
      get<3>(w) += (1LL << (emp[get<0>(v)].second * 3));
      get<2>(w)++;
      get<0>(w)++;
      if (D.find(w) == D.end()) {
        D[w] = D[v] + 1;
        Q.push(w);
      }
    }
  }
  cout << ret << "\n";
  return 0;
}
