#include <bits/stdc++.h>
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;
using namespace std;
template <class TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char* sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 2000, F = 9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  map<vector<long long>, long long> dp = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0}};
  long long n, cur = 1;
  cin >> n;
  for (long long i = (long long)0; i < (long long)n; i++) {
    long long from, to;
    cin >> from >> to;
    auto nxt = dp;
    nxt.clear();
    for (auto& pp : dp) {
      auto& cnts = pp.first;
      auto& tm = pp.second;
      for (auto& w : cnts) {
        if (0) cout << w << " ";
      }
      if (0) cout << "\n";
      if (0) cout << tm << "\n";
      for (long long j = (long long)1; j < (long long)F + 1; j++) {
        auto nxt_cnts = cnts;
        for (long long k = (long long)1; k < (long long)F + 1; k++) {
          if (abs(k - j) + abs(k - cur) == abs(j - cur) or
              abs(k - j) + abs(k - from) == abs(from - j)) {
            nxt_cnts[k] = 0;
          }
        }
        nxt_cnts[to]++;
        if (accumulate((nxt_cnts).begin(), (nxt_cnts).end(), 0) <= 4) {
          long long cnd = tm + abs(cur - j) + abs(from - j);
          if (nxt.find(nxt_cnts) == nxt.end()) {
            nxt[nxt_cnts] = cnd;
          } else {
            nxt[nxt_cnts] = min(nxt[nxt_cnts], cnd);
          }
        }
      }
    }
    cur = from;
    swap(dp, nxt);
  }
  long long res = INF;
  for (auto& pp : dp) {
    auto& cnts = pp.first;
    auto& tm = pp.second;
    long long mi = F + 1, ma = 0;
    for (long long i = (long long)1; i < (long long)F + 1; i++) {
      if (cnts[i]) {
        mi = min(mi, i);
        ma = max(ma, i);
      }
    }
    for (auto& w : cnts) {
      if (0) cout << w << " ";
    }
    if (0) cout << "\n";
    if (0) cout << tm << "\n";
    res = min({res, 2 * n + tm + abs(mi - ma) + abs(cur - mi),
               2 * n + tm + abs(mi - ma) + abs(cur - ma)});
  }
  cout << res << "\n";
  return 0;
}
