#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
  if (b == 0LL) return 1LL;
  if (b == 1LL) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1LL) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
const int N = 2002;
int A[N], B[N];
map<vector<int>, int> dp[N][10];
int n;
void redo(int &a, int &b, int &c, int &d, int piso) {
  if (a == piso) a = 0;
  if (b == piso) b = 0;
  if (c == piso) c = 0;
  if (d == piso) d = 0;
  vector<int> v = {a, b, c, d};
  sort(v.begin(), v.end());
  a = v[0], b = v[1], c = v[2], d = v[3];
}
int solve(int id, int piso, int a, int b, int c, int d) {
  redo(a, b, c, d, piso);
  vector<int> cur = {a, b, c, d};
  if (dp[id][piso].count(cur)) return dp[id][piso][cur];
  dp[id][piso][cur] = 1e9;
  if (id == n) {
    int mn;
    int mx = d;
    if (mx == 0) return dp[id][piso][cur] = 0;
    if (a)
      mn = a;
    else if (b)
      mn = b;
    else if (c)
      mn = c;
    else
      mn = d;
    assert(mn != 0 and mn <= mx);
    if (piso >= mx) return dp[id][piso][cur] = piso - mn;
    if (piso <= mn) return dp[id][piso][cur] = mx - piso;
    return dp[id][piso][cur] = min(abs(piso - mn), abs(piso - mx)) + mx - mn;
  }
  int na, nb, nc, nd;
  if (a == 0) {
    int nxt = A[id];
    na = a, nb = b, nc = c, nd = d;
    if (piso < nxt) {
      if (a <= nxt and a >= piso) na = 0;
      if (b <= nxt and b >= piso) nb = 0;
      if (c <= nxt and c >= piso) nc = 0;
      if (d <= nxt and d >= piso) nd = 0;
    } else {
      if (a >= nxt and a <= piso) na = 0;
      if (b >= nxt and b <= piso) nb = 0;
      if (c >= nxt and c <= piso) nc = 0;
      if (d >= nxt and d <= piso) nd = 0;
    }
    dp[id][piso][cur] =
        min(dp[id][piso][cur],
            solve(id + 1, nxt, B[id], nb, nc, nd) + abs(piso - nxt));
  }
  int nxt = a;
  na = a, nb = b, nc = c, nd = d;
  if (piso < nxt) {
    if (a <= nxt and a >= piso) na = 0;
    if (b <= nxt and b >= piso) nb = 0;
    if (c <= nxt and c >= piso) nc = 0;
    if (d <= nxt and d >= piso) nd = 0;
  } else {
    if (a >= nxt and a <= piso) na = 0;
    if (b >= nxt and b <= piso) nb = 0;
    if (c >= nxt and c <= piso) nc = 0;
    if (d >= nxt and d <= piso) nd = 0;
  }
  if (nxt != 0)
    dp[id][piso][cur] = min(dp[id][piso][cur],
                            solve(id, nxt, na, nb, nc, nd) + abs(piso - nxt));
  nxt = b;
  na = a, nb = b, nc = c, nd = d;
  if (piso < nxt) {
    if (a <= nxt and a >= piso) na = 0;
    if (b <= nxt and b >= piso) nb = 0;
    if (c <= nxt and c >= piso) nc = 0;
    if (d <= nxt and d >= piso) nd = 0;
  } else {
    if (a >= nxt and a <= piso) na = 0;
    if (b >= nxt and b <= piso) nb = 0;
    if (c >= nxt and c <= piso) nc = 0;
    if (d >= nxt and d <= piso) nd = 0;
  }
  if (nxt != 0)
    dp[id][piso][cur] = min(dp[id][piso][cur],
                            solve(id, nxt, na, nb, nc, nd) + abs(piso - nxt));
  nxt = c;
  na = a, nb = b, nc = c, nd = d;
  if (piso < nxt) {
    if (a <= nxt and a >= piso) na = 0;
    if (b <= nxt and b >= piso) nb = 0;
    if (c <= nxt and c >= piso) nc = 0;
    if (d <= nxt and d >= piso) nd = 0;
  } else {
    if (a >= nxt and a <= piso) na = 0;
    if (b >= nxt and b <= piso) nb = 0;
    if (c >= nxt and c <= piso) nc = 0;
    if (d >= nxt and d <= piso) nd = 0;
  }
  if (nxt != 0)
    dp[id][piso][cur] = min(dp[id][piso][cur],
                            solve(id, nxt, na, nb, nc, nd) + abs(piso - nxt));
  nxt = d;
  na = a, nb = b, nc = c, nd = d;
  if (piso < nxt) {
    if (a <= nxt and a >= piso) na = 0;
    if (b <= nxt and b >= piso) nb = 0;
    if (c <= nxt and c >= piso) nc = 0;
    if (d <= nxt and d >= piso) nd = 0;
  } else {
    if (a >= nxt and a <= piso) na = 0;
    if (b >= nxt and b <= piso) nb = 0;
    if (c >= nxt and c <= piso) nc = 0;
    if (d >= nxt and d <= piso) nd = 0;
  }
  if (nxt != 0)
    dp[id][piso][cur] = min(dp[id][piso][cur],
                            solve(id, nxt, na, nb, nc, nd) + abs(piso - nxt));
  return dp[id][piso][cur];
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  cout << solve(0, 1, 0, 0, 0, 0) + 2 * n << "\n";
}
