#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int inf = 0x3f3f3f3f;
int x[maxn], y[maxn], dp[maxn][10][10][10][10], n;
int dfs(int k, int cur, int a, int b, int c) {
  if (dp[k][cur][a][b][c] != -1) return dp[k][cur][a][b][c];
  int &res = dp[k][cur][a][b][c];
  res = inf;
  if (k > n) {
    if (a == 0 && b == 0 && c == 0) return res = 0;
    if (a) res = min(res, dfs(k, a, 0, b, c) + abs(cur - a) + 1);
    if (b) res = min(res, dfs(k, b, a, 0, c) + abs(cur - b) + 1);
    if (c) res = min(res, dfs(k, c, a, b, 0) + abs(cur - c) + 1);
  } else {
    if (a) res = min(res, dfs(k, a, 0, b, c) + abs(cur - a) + 1);
    if (b) res = min(res, dfs(k, b, a, 0, c) + abs(cur - b) + 1);
    if (c) res = min(res, dfs(k, c, a, b, 0) + abs(cur - c) + 1);
    if (a && b && c) {
      res = min(res, dfs(k + 1, y[k], a, b, c) + abs(cur - x[k]) +
                         abs(x[k] - y[k]) + 2);
      res = min(
          res, dfs(k + 1, a, y[k], b, c) + abs(cur - x[k]) + abs(x[k] - a) + 2);
      res = min(
          res, dfs(k + 1, b, a, y[k], c) + abs(cur - x[k]) + abs(x[k] - b) + 2);
      res = min(
          res, dfs(k + 1, c, a, b, y[k]) + abs(cur - x[k]) + abs(x[k] - c) + 2);
    } else {
      if (!a)
        res = min(res, dfs(k + 1, x[k], y[k], b, c) + abs(cur - x[k]) + 1);
      if (!b)
        res = min(res, dfs(k + 1, x[k], a, y[k], c) + abs(cur - x[k]) + 1);
      if (!c)
        res = min(res, dfs(k + 1, x[k], a, b, y[k]) + abs(cur - x[k]) + 1);
    }
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", x + i, y + i);
  memset(dp, -1, sizeof dp);
  printf("%d\n", dfs(1, 1, 0, 0, 0));
  return 0;
}
