#include <bits/stdc++.h>
using namespace std;
const int N = 2005, MX = 1e6;
int n;
pair<int, int> p[N];
int dp[2010][3][9][720];
bool ok[2010][3][9][720];
vector<int> hs[720];
map<vector<int>, int> M;
inline bool cmp(int a, int b) { return a > b; }
int dfs(int i, int op, int fl, int msk) {
  if (i == n + 1 && msk == 714) return 0;
  if (fl == 9 || fl == -1) return MX;
  if (ok[i][op][fl][msk]) return dp[i][op][fl][msk];
  ok[i][op][fl][msk] = 1;
  int &ret = dp[i][op][fl][msk];
  vector<int> tmp = hs[msk];
  int cg = 0;
  for (int k = 0; k < 4; ++k) {
    if (tmp[k] == fl + 1) {
      tmp[k] = 0;
      ++cg;
    }
  }
  if (cg) {
    sort(tmp.begin(), tmp.end(), cmp);
    return ret = dfs(i, 0, fl, M[tmp]) + cg;
  }
  if (i <= n && p[i].first == fl + 1 && tmp[3] == 0) {
    tmp[3] = p[i].second;
    sort(tmp.begin(), tmp.end(), cmp);
    return ret = dfs(i + 1, 0, fl, M[tmp]) + 1;
  }
  if (op == 0) {
    return ret = min(dfs(i, 1, fl + 1, msk), dfs(i, 2, fl - 1, msk)) + 1;
  } else if (op == 1) {
    return ret = dfs(i, 1, fl + 1, msk) + 1;
  } else if (op == 2) {
    return ret = dfs(i, 2, fl - 1, msk) + 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &p[i].first, &p[i].second);
  }
  int cnt = -1;
  for (int i = 9; i >= 0; --i)
    for (int j = i; j >= 0; --j)
      for (int k = j; k >= 0; --k)
        for (int h = k; h >= 0; --h) {
          ++cnt;
          hs[cnt].push_back(i);
          hs[cnt].push_back(j);
          hs[cnt].push_back(k);
          hs[cnt].push_back(h);
          M[hs[cnt]] = cnt;
        }
  cout << dfs(1, 1, 0, 714);
}
