#include <bits/stdc++.h>
using namespace std;
int N;
int a[2002], b[2002];
vector<pair<pair<int, int>, pair<int, int> > > v;
int back[10000];
int INF = 1000000000;
int memo[715][10][2002][2];
int faire(int s, int minus) {
  int ans = 0;
  if (v[s].first.first != minus) {
    ans *= 10;
    ans += v[s].first.first;
  }
  if (v[s].first.second != minus) {
    ans *= 10;
    ans += v[s].first.second;
  }
  if (v[s].second.first != minus) {
    ans *= 10;
    ans += v[s].second.first;
  }
  if (v[s].second.second != minus) {
    ans *= 10;
    ans += v[s].second.second;
  }
  return ans;
}
int refaire(int s, int plus) {
  if (v[s].second.second <= plus)
    return 1000 * v[s].first.second + 100 * v[s].second.first +
           10 * v[s].second.second + plus;
  else if (v[s].second.first <= plus)
    return 1000 * v[s].first.second + 100 * v[s].second.first + 10 * plus +
           v[s].second.second;
  else if (v[s].first.second <= plus)
    return 1000 * v[s].first.second + 100 * plus + 10 * v[s].second.first +
           v[s].second.second;
  else
    return 1000 * plus + 100 * v[s].first.second + 10 * v[s].second.first +
           v[s].second.second;
}
int dp(int s, int e, int x, int sens) {
  if (memo[s][e][x][sens] >= 0) return memo[s][e][x][sens];
  if (x == N && s == 0) return 0;
  if (v[s].first.first == e || v[s].first.second == e ||
      v[s].second.first == e || v[s].second.second == e) {
    int ss = back[faire(s, e)];
    return (memo[s][e][x][sens] = min(dp(ss, e, x, 0), dp(ss, e, x, 1)));
  }
  if (v[s].first.first == 0 && x <= N - 1 && a[x] == e) {
    int ss = back[refaire(s, b[x])];
    return (memo[s][e][x][sens] =
                min(dp(ss, e, x + 1, 0), dp(ss, e, x + 1, 1)));
  }
  int poss = INF;
  if (e < 9 && !sens) poss = min(dp(s, e + 1, x, sens), poss) + 1;
  if (e > 1 && sens) poss = min(dp(s, e - 1, x, sens), poss) + 1;
  return (memo[s][e][x][sens] = poss);
}
int main() {
  scanf("%d", &N);
  for (int i = int(0); i <= int(N - 1); i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  for (int a = int(0); a <= int(9); a++)
    for (int b = int(a); b <= int(9); b++)
      for (int c = int(b); c <= int(9); c++)
        for (int d = int(c); d <= int(9); d++) {
          v.push_back(make_pair(pair<int, int>(a, b), pair<int, int>(c, d)));
          back[1000 * a + 100 * b + 10 * c + d] = v.size() - 1;
        }
  for (int i = int(0); i <= int(714); i++)
    for (int j = int(1); j <= int(9); j++)
      for (int k = int(0); k <= int(N); k++)
        for (int l = int(0); l <= int(1); l++) memo[i][j][k][l] = -1;
  cout << dp(0, 1, 0, 0) + 2 * N << endl;
  return 0;
}
