#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000 + 2][2];
int f[2001][720][10];
vector<int> x;
map<vector<int>, int> xx;
map<int, vector<int> > xr;
void pre(int g, vector<int> y) {
  if (g == 0) {
    sort(y.begin(), y.end());
    xx[y];
    return;
  }
  for (int i = 0; i < 10; i++) {
    y.push_back(i);
    pre(g - 1, y);
    y.pop_back();
  }
}
vector<int> give(vector<int> x) {
  sort(x.begin(), x.end());
  return x;
}
int get(int rem, int x, int el) {
  if (rem == 0 && x == 0) return 0;
  if (f[rem][x][el] != 0) return f[rem][x][el];
  vector<int> g = xr[x], h = xr[x];
  int ans = 1000000;
  for (int i = 0; i < g.size(); i++) {
    if (g[i] == 0) continue;
    swap(h[i], h[3]);
    h.pop_back();
    h.push_back(0);
    ans = min(ans, 1 + abs(el - g[i]) + get(rem, xx[give(h)], g[i]));
    h = g;
  }
  if (h[0] == 0 && rem != 0) {
    h[0] = a[n - rem + 1][1];
    ans = min(ans, 1 + abs(el - a[n - rem + 1][0]) +
                       get(rem - 1, xx[give(h)], a[n - rem + 1][0]));
  }
  return f[rem][x][el] = ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1];
  pre(4, x);
  int max = 0;
  for (auto it = xx.begin(); it != xx.end(); it++) it->second = max++;
  for (auto it = xx.begin(); it != xx.end(); it++) xr[it->second] = it->first;
  cout << get(n, 0, 1) << endl;
}
