#include <bits/stdc++.h>
using namespace std;
short int n, a[2002], b[2002];
unordered_map<short int, short int> dp[2001][10];
short int go(short int id, short int cur, vector<short int> v) {
  if (id == n and (short int) v.size() == 0) return 0;
  short int hsh = 0;
  for (auto i : v) {
    hsh = hsh * 10 + i;
  }
  if (dp[id][cur].count(hsh)) {
    return dp[id][cur][hsh];
  }
  short int ans = 32767;
  if ((short int)v.size() < 4 and id < n) {
    vector<short int> temp = v;
    temp.push_back(b[id]);
    sort((temp).begin(), (temp).end());
    ans = min(1 * ans, abs(a[id] - cur) + 1 + go(id + 1, a[id], temp));
  }
  for (short int i = 0; i < (short int)v.size(); i++) {
    vector<short int> temp;
    for (short int j = 0; j < (short int)v.size(); j++) {
      if (i == j) continue;
      temp.push_back(v[j]);
    }
    sort((temp).begin(), (temp).end());
    ans = min(1 * ans, abs(v[i] - cur) + 1 + go(id, v[i], temp));
  }
  return dp[id][cur][hsh] = ans;
}
void solve() {
  cin >> n;
  for (short int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  cout << go(0, 1, {}) << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  short int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
