#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int nint() {
  int x;
  scanf("%d", &x);
  return x;
}
const long long mod = 1000000000 + 7;
int m;
int n;
long long ans;
int a[2050], b[2050];
int table[2050][1050];
vector<int> split(int x) {
  vector<int> ans;
  for (int i = 0; i < (3); i++) {
    if (x % 10) ans.emplace_back(x % 10);
    x /= 10;
  }
  return ans;
}
inline int merge(vector<int> &v, int x) {
  int ans = 0;
  for (int i = 0; i < (3); i++) {
    ans *= 10;
    if (i < ((int)(v).size()) && v[i] != x) ans += v[i];
  }
  return ans;
}
inline int get1(int l, int r, int x) {
  return min(abs(x - l), abs(x - r)) + r - l;
}
inline int get2(int l, int r, int x1, int x2) {
  return min(abs(x1 - l) + abs(x2 - r), abs(x1 - r) + abs(x2 - l)) + r - l;
}
int getans(int p, int cur) {
  int &ans = table[p][cur];
  if (ans != -1) return ans;
  int pos = a[p];
  vector<int> v = split(cur);
  v.emplace_back(b[p]);
  sort((v).begin(), (v).end());
  if (p == n - 1) {
    ans = get1(v[0], v.back(), pos);
    return ans;
  }
  ans = mod;
  int ne = a[p + 1];
  if (((int)(v).size()) < 4)
    ans = min(ans, getans(p + 1, merge(v, ne)) + abs(ne - pos));
  for (int i = 0; i < (((int)(v).size())); i++) {
    if (i && (v[i] == v[i - 1])) continue;
    for (int j = i; j < ((int)(v).size()); j++) {
      if (j < ((int)(v).size()) - 1 && v[j] == v[j + 1]) continue;
      int tmp = get2(v[i], v[j], pos, ne);
      vector<int> tv;
      for (int k = 0; k < (((int)(v).size())); k++) {
        if (k < i || k > j) tv.emplace_back(v[k]);
      }
      ans = min(ans, tmp + getans(p + 1, merge(tv, ne)));
    }
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i] >> b[i];
  memset(table, -1, sizeof(table));
  cout << getans(0, 0) + a[0] - 1 + 2 * n;
}
