#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n;
int f[N][10][10][10][10], st[N], en[N];
int dp(int k, int now, int a, int b, int c, int d) {
  if (k == n + 1 && d == 0) return 0;
  if (a == 0 && f[k][b][c][d][now] >= 0) {
    if (0)
      printf("pre: f[%d][%d][%d][%d][%d] = %d\n", k, b, c, d, now,
             f[k][b][c][d][now]);
    return f[k][b][c][d][now];
  }
  int res = 1000000;
  if (d) {
    res = min(res, dp(k, d, 0, a, b, c) + abs(now - d));
    if (c) {
      res = min(res, dp(k, c, 0, a, b, d) + abs(now - c));
      if (b) {
        res = min(res, dp(k, b, 0, a, c, d) + abs(now - b));
        if (a) {
          res = min(res, dp(k, a, 0, b, c, d) + abs(now - a));
        }
      }
    }
  }
  if (a) return res;
  if (k == n + 1) return f[k][b][c][d][now] = res;
  int t[4] = {en[k], b, c, d};
  sort(t, t + 4);
  res = min(res, dp(k + 1, st[k], t[0], t[1], t[2], t[3]) + abs(now - st[k]));
  return f[k][b][c][d][now] = res;
}
int main() {
  memset(f, -1, sizeof(f));
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &st[i], &en[i]);
  printf("%d\n", dp(1, 1, 0, 0, 0, 0) + (n << 1));
  return 0;
}
