#include <bits/stdc++.h>
using namespace std;
long long N;
long long arr[2005];
long long barr[2005];
long long memo[2005][10][10][10][10];
bool vis[2005][10][10][10][10];
long long dp(long long x, long long p, long long a, long long b, long long c) {
  if (vis[x][p][a][b][c]) return memo[x][p][a][b][c];
  if (x > N) {
    if (!a && !b && !c) return 0;
    long long ans = 1e9;
    if (a) ans = min(ans, dp(x, a, 0, b, c) + abs(p - a));
    if (b) ans = min(ans, dp(x, b, a, 0, c) + abs(p - b));
    if (c) ans = min(ans, dp(x, c, a, b, 0) + abs(p - c));
    vis[x][p][a][b][c] = 1;
    return memo[x][p][a][b][c] = ans;
  }
  long long ans = 1e9;
  vis[x][p][a][b][c] = true;
  if (a) ans = min(ans, dp(x, a, 0, b, c) + abs(p - a));
  if (b) ans = min(ans, dp(x, b, a, 0, c) + abs(p - b));
  if (c) ans = min(ans, dp(x, c, a, b, 0) + abs(p - c));
  if (a && b && c) {
    ans = min(ans, dp(x + 1, barr[x], a, b, c) + abs(p - arr[x]) +
                       abs(arr[x] - barr[x]));
    ans = min(ans,
              dp(x + 1, a, barr[x], b, c) + abs(p - arr[x]) + abs(arr[x] - a));
    ans = min(ans,
              dp(x + 1, b, a, barr[x], c) + abs(p - arr[x]) + abs(arr[x] - b));
    ans = min(ans,
              dp(x + 1, c, a, b, barr[x]) + abs(p - arr[x]) + abs(arr[x] - c));
  } else {
    if (!a)
      ans = min(ans, dp(x + 1, arr[x], barr[x], b, c) + abs(p - arr[x]));
    else if (!b)
      ans = min(ans, dp(x + 1, arr[x], a, barr[x], c) + abs(p - arr[x]));
    else
      ans = min(ans, dp(x + 1, arr[x], a, b, barr[x]) + abs(p - arr[x]));
  }
  return memo[x][p][a][b][c] = ans;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N;
  for (long long i = 1; i <= N; i++) cin >> arr[i] >> barr[i];
  cout << dp(1, 1, 0, 0, 0) + N + N << "\n";
  return 0;
}
