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