#include <bits/stdc++.h>
using namespace std;
int dp[2005][11][11][11][11];
int a[2005], b[2005];
int n;
int dfs(int num, int cnt, int x, int y, int z) {
  int mx = 1e8;
  if (dp[num][cnt][x][y][z] != 0) {
    return dp[num][cnt][x][y][z];
  }
  if (x != 0) {
    mx = min(mx, dfs(num, x, 0, y, z) + abs(cnt - x) + 1);
  }
  if (y != 0) {
    mx = min(mx, dfs(num, y, x, 0, z) + abs(cnt - y) + 1);
  }
  if (z != 0) {
    mx = min(mx, dfs(num, z, x, y, 0) + abs(cnt - z) + 1);
  }
  if (num > n) {
    if (x == 0 && y == 0 && z == 0) {
      return 0;
    } else {
      return dp[num][cnt][x][y][z] = mx;
    }
  }
  if (x != 0 && y != 0 && z != 0) {
    mx = min(mx, dfs(num + 1, b[num], x, y, z) + abs(cnt - a[num]) +
                     abs(a[num] - b[num]) + 2);
    mx = min(mx, dfs(num + 1, x, b[num], y, z) + abs(cnt - a[num]) +
                     abs(a[num] - x) + 2);
    mx = min(mx, dfs(num + 1, y, x, b[num], z) + abs(cnt - a[num]) +
                     abs(a[num] - y) + 2);
    mx = min(mx, dfs(num + 1, z, x, y, b[num]) + abs(cnt - a[num]) +
                     abs(a[num] - z) + 2);
  } else {
    if (x == 0) {
      mx = min(mx, dfs(num + 1, a[num], b[num], y, z) + abs(cnt - a[num]) + 1);
    } else if (y == 0) {
      mx = min(mx, dfs(num + 1, a[num], x, b[num], z) + abs(cnt - a[num]) + 1);
    } else {
      mx = min(mx, dfs(num + 1, a[num], x, y, b[num]) + abs(cnt - a[num]) + 1);
    }
  }
  return dp[num][cnt][x][y][z] = mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, 0, sizeof(dp));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  cout << dfs(1, 1, 0, 0, 0) << endl;
  return 0;
}
