#include <bits/stdc++.h>
using namespace std;
map<pair<pair<int, int>, int>, int> dp;
int fuck[] = {1000, 100, 10, 1};
int starts[2005];
int finish[2005];
int n;
int get(int done, int status, int flr) {
  if (done == n) return 0;
  array<int, 4> a;
  for (int i = 0; i < 4; i++) {
    a[i] = status % 10;
    status /= 10;
  }
  sort((a).begin(), (a).end());
  for (auto i : a) status = (status * 10 + i);
  if (dp.count(make_pair(make_pair(done, status), flr)))
    return dp[make_pair(make_pair(done, status), flr)];
  int ans = INT_MAX;
  int in_lift = 4 - count((a).begin(), (a).end(), 0);
  for (int i = 4 - in_lift; i < 4; i++) {
    ans = min(ans,
              abs(a[i] - flr) + get(done + 1, status - a[i] * fuck[i], a[i]));
  }
  int pickup = done + in_lift;
  if (in_lift < 4 and pickup < n)
    ans = min(ans,
              abs(starts[pickup] - flr) +
                  get(done, status + fuck[0] * finish[pickup], starts[pickup]));
  return dp[make_pair(make_pair(done, status), flr)] = ans;
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> starts[i] >> finish[i];
  cout << get(0, 0, 1) + 2 * n << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
