#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int big = 4.19e18 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U>
void mineq(T& a, U b) {
  if (a > b) {
    a = b;
  }
}
template <class T, class U>
void maxeq(T& a, U b) {
  if (a < b) {
    a = b;
  }
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
template <class T>
void SO(T& ve) {
  sort(ve.begin(), ve.end());
}
template <class T>
void REV(T& ve) {
  reverse(ve.begin(), ve.end());
}
int LBI(vector<int>& ar, int in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int UBI(vector<int>& ar, int in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, i, j, p, q, r;
  cin >> n;
  static int sta[2000] = {0};
  static int gol[2000] = {0};
  for (i = 0; i < n; i++) {
    cin >> sta[i] >> gol[i];
  }
  static int dp[2000][10][10][10] = {0};
  dp[0][0][0][0] = -mod + n + n + sta[0] - 1;
  for (i = 0; i < n - 1; i++) {
    for (int pp = 0; pp <= 9; pp++) {
      for (int qq = pp; qq <= 9; qq++) {
        for (int rr = qq; rr <= 9; rr++) {
          if (dp[i][pp][qq][rr] == 0) {
            continue;
          }
          array<int, 4> hi;
          hi[0] = pp;
          hi[1] = qq;
          hi[2] = rr;
          hi[3] = gol[i];
          int gen = dp[i][pp][qq][rr];
          int bas = sta[i];
          int s = gol[i];
          SO(hi);
          for (int h = 0; h < 4; h++) {
            if (hi[h] == 0) {
              mineq(dp[i + 1][hi[1]][hi[2]][hi[3]],
                    gen + abs(bas - sta[i + 1]));
            } else {
              auto it = hi;
              for (j = 0; j < 4; j++) {
                if (min(hi[h], min(sta[i + 1], bas)) <= it[j] &&
                    it[j] <= max(hi[h], max(sta[i + 1], bas))) {
                  it[j] = 0;
                }
              }
              SO(it);
              mineq(dp[i + 1][it[1]][it[2]][it[3]],
                    gen + abs(bas - hi[h]) + abs(hi[h] - sta[i + 1]));
            }
          }
        }
      }
    }
  }
  int ans = mod;
  for (int pp = 0; pp <= 9; pp++) {
    for (int qq = pp; qq <= 9; qq++) {
      for (int rr = qq; rr <= 9; rr++) {
        if (dp[i][pp][qq][rr] == 0) {
          continue;
        }
        array<int, 4> hi;
        hi[0] = pp;
        hi[1] = qq;
        hi[2] = rr;
        hi[3] = gol[n - 1];
        int st = sta[n - 1], ue = sta[n - 1];
        for (int h = 0; h < 4; h++) {
          if (hi[h] == 0) {
            continue;
          }
          mineq(st, hi[h]);
          maxeq(ue, hi[h]);
        }
        mineq(ans, dp[i][pp][qq][rr] + sta[n - 1] + ue - st - st + mod);
        mineq(ans, dp[i][pp][qq][rr] - sta[n - 1] + ue + ue - st + mod);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
