#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
struct info {
  int i, v, fl, d;
  info(int i, int v, int fl, int d) : i(i), v(v), fl(fl), d(d) {}
  bool operator<(const info &other) const { return d > other.d; }
};
int n;
int ans;
int in[2010], out[2010];
int dist[2010][10][1000];
vector<int> decompose(int x) {
  vector<int> v;
  while (x) v.push_back(x % 10), x /= 10;
  return v;
}
int compose(const vector<int> &v) {
  int x = 0;
  for (auto val : v) x = x * 10 + val;
  return x;
}
vector<int> remove(const vector<int> &v, int j, int k) {
  vector<int> res(v);
  res.erase(remove_if(res.begin(), res.end(),
                      [&j, &k](int x) { return j <= x && x <= k; }),
            res.end());
  return res;
}
void update(int &dp, int val) { dp = min(dp, val); }
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k, fl, outv;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> in[i] >> out[i];
  memset(dist, 0x3f3f3f3f, sizeof dist);
  dist[1][1][0] = 0;
  for (i = 1; i <= n; ++i)
    for (fl = 1; fl <= 9; ++fl)
      for (outv = 0; outv < 1000; ++outv) {
        if (dist[i][fl][outv] == 0x3f3f3f3f) continue;
        auto v = decompose(outv);
        v.push_back(out[i]);
        sort(v.begin(), v.end());
        if (v.size() < 4) {
          update(dist[i + 1][in[i]][compose(v)],
                 dist[i][fl][outv] + abs(in[i] - fl));
        }
        for (j = 0; j < v.size(); ++j)
          for (k = j; k < v.size(); ++k) {
            auto u = remove(v, v[j], v[k]);
            int newoutv = compose(u);
            int dist1 = dist[i][fl][outv] + abs(in[i] - fl) +
                        abs(v[j] - in[i]) + v[k] - v[j];
            int dist2 = dist[i][fl][outv] + abs(in[i] - fl) +
                        abs(v[k] - in[i]) + v[k] - v[j];
            update(dist[i + 1][v[k]][newoutv], dist1);
            update(dist[i + 1][v[j]][newoutv], dist2);
          }
      }
  for (ans = 0x3f3f3f3f, fl = 1; fl <= 9; ++fl)
    ans = min(ans, dist[n + 1][fl][0]);
  cout << ans + 2 * n << '\n';
  return 0;
}
