#include <bits/stdc++.h>
using namespace std;
const int N = 3e3, M = 11;
int n;
int a[N], b[N];
int f[N][M][M][M][M];
int dfs(int i, int k, int x, int y, int z) {
  if (f[i][k][x][y][z]) return f[i][k][x][y][z];
  int t = 1e9;
  if (i > n) {
    if (!(x | y | z)) return 0;
    if (x) t = min(t, dfs(i, x, 0, y, z) + abs(k - x) + 1);
    if (y) t = min(t, dfs(i, y, x, 0, z) + abs(k - y) + 1);
    if (z) t = min(t, dfs(i, z, x, y, 0) + abs(k - z) + 1);
    return f[i][k][x][y][z] = t;
  }
  if (x) t = min(t, dfs(i, x, 0, y, z) + abs(k - x) + 1);
  if (y) t = min(t, dfs(i, y, x, 0, z) + abs(k - y) + 1);
  if (z) t = min(t, dfs(i, z, x, y, 0) + abs(k - z) + 1);
  int S = abs(k - a[i]);
  if (x && y && z) {
    t = min(t, dfs(i + 1, b[i], x, y, z) + S + abs(b[i] - a[i]) + 2);
    t = min(t, dfs(i + 1, x, b[i], y, z) + S + abs(x - a[i]) + 2);
    t = min(t, dfs(i + 1, y, x, b[i], z) + S + abs(y - a[i]) + 2);
    t = min(t, dfs(i + 1, z, x, y, b[i]) + S + abs(z - a[i]) + 2);
  } else if (!x)
    t = min(t, dfs(i + 1, a[i], b[i], y, z) + S + 1);
  else if (!y)
    t = min(t, dfs(i + 1, a[i], x, b[i], z) + S + 1);
  else
    t = min(t, dfs(i + 1, a[i], x, y, b[i]) + S + 1);
  return f[i][k][x][y][z] = t;
}
int main() {
  cin >> n;
  for (int i = 0; ++i <= n;) cin >> a[i] >> b[i];
  cout << dfs(1, 1, 0, 0, 0);
  return 0;
}
