#include <bits/stdc++.h>
using namespace std;
int n, A[2005], B[2005];
int dp[2005][11][11][11][11];
int dfs(int i, int cur, int a, int b, int c) {
  if (dp[i][cur][a][b][c] != -1) return dp[i][cur][a][b][c];
  int res = 0x3f3f3f3f;
  if (i > n) {
    if (!a && !b && !c) res = 0;
    if (a != 0) res = min(res, dfs(i, a, 0, b, c) + abs(cur - a) + 1);
    if (b != 0) res = min(res, dfs(i, b, a, 0, c) + abs(cur - b) + 1);
    if (c != 0) res = min(res, dfs(i, c, a, b, 0) + abs(cur - c) + 1);
    return dp[i][cur][a][b][c] = res;
  }
  if (a) res = min(res, dfs(i, a, 0, b, c) + abs(cur - a) + 1);
  if (b) res = min(res, dfs(i, b, a, 0, c) + abs(cur - b) + 1);
  if (c) res = min(res, dfs(i, c, a, b, 0) + abs(cur - c) + 1);
  if (a && b && c) {
    res = min(res, dfs(i + 1, B[i], a, b, c) + abs(cur - A[i]) +
                       abs(A[i] - B[i]) + 2);
    res = min(res,
              dfs(i + 1, a, B[i], b, c) + abs(cur - A[i]) + abs(A[i] - a) + 2);
    res = min(res,
              dfs(i + 1, b, a, B[i], c) + abs(cur - A[i]) + abs(A[i] - b) + 2);
    res = min(res,
              dfs(i + 1, c, a, b, B[i]) + abs(cur - A[i]) + abs(A[i] - c) + 2);
  } else {
    if (!a)
      res = min(res, dfs(i + 1, A[i], B[i], b, c) + abs(cur - A[i]) + 1);
    else if (!b)
      res = min(res, dfs(i + 1, A[i], a, B[i], c) + abs(cur - A[i]) + 1);
    else if (!c)
      res = min(res, dfs(i + 1, A[i], a, b, B[i]) + abs(cur - A[i]) + 1);
  }
  return dp[i][cur][a][b][c] = res;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i] >> B[i];
  cout << dfs(1, 1, 0, 0, 0) << '\n';
}
