#include <bits/stdc++.h>
using namespace std;
void chmin(int& a, int b) { a = min(a, b); }
int dp[2][10000][10];
int main() {
  int N, A[2000], B[2000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  const int INF = 1e9;
  const int pow10[] = {1, 10, 100, 1000};
  for (int i = 0; i < 10000; i++)
    for (int j = 1; j < 10; j++) dp[0][i][j] = INF;
  dp[0][0][1] = 0;
  for (int t = 0; t <= N; t++) {
    for (int i = 0; i < 10000; i++)
      for (int j = 1; j < 10; j++) dp[1 - t % 2][i][j] = INF;
    for (int i = 9999; i >= 0; i--)
      for (int now = 1; now < 10; now++) {
        if (dp[t % 2][i][now] == INF) continue;
        int tmp = i, base = 1, absent = 0;
        for (int k = 0; k < 4; k++) {
          int n = tmp % 10;
          if (n > 0) {
            if (k == absent) absent++;
            chmin(dp[t % 2][i - base * n][n], dp[t % 2][i][now] + abs(n - now));
          }
          base *= 10;
          tmp /= 10;
        }
        if (t < N && absent < 4) {
          chmin(dp[1 - t % 2][i + pow10[absent] * B[t]][A[t]],
                dp[t % 2][i][now] + abs(A[t] - now));
        }
      }
  }
  int ans = INF;
  for (int now = 1; now < 10; now++) chmin(ans, dp[N % 2][0][now]);
  ans += 2 * N;
  cout << ans << endl;
  return 0;
}
