#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long mod = 1000000007;
const int N = 2010;
void upd(int &r, int val) {
  if (r > val) r = val;
}
int in[N], out[N];
int dp[2][10][10][10][10];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %d", in + i, out + i);
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 10; k++)
        for (int s = 0; s < 10; s++) dp[0][i][j][k][s] = INF;
  dp[0][1][0][0][0] = 0;
  bool fl = 0;
  for (int it = 1; it <= n + 1; it++) {
    for (int a = 9; a >= 0; a--)
      for (int b = 9; b >= 0; b--)
        for (int c = 9; c >= 0; c--)
          for (int f = 1; f <= 9; f++) {
            int prev = dp[fl][f][a][b][c];
            if (a) upd(dp[fl][a][0][b][c], prev + abs(a - f));
            if (b) upd(dp[fl][b][a][0][c], prev + abs(b - f));
            if (c) upd(dp[fl][c][a][b][0], prev + abs(c - f));
            dp[fl ^ 1][f][a][b][c] = INF;
          }
    if (it == n + 1) break;
    for (int a = 9; a >= 0; a--)
      for (int b = 9; b >= 0; b--)
        for (int c = 9; c >= 0; c--)
          for (int f = 1; f <= 9; f++) {
            int prev = dp[fl][f][a][b][c];
            int xi = in[it], yi = out[it];
            if (!a) upd(dp[fl ^ 1][xi][yi][b][c], prev + abs(xi - f));
            if (!b) upd(dp[fl ^ 1][xi][a][yi][c], prev + abs(xi - f));
            if (!c) upd(dp[fl ^ 1][xi][a][b][yi], prev + abs(xi - f));
            if (a && b && c) {
              upd(dp[fl ^ 1][a][yi][b][c], prev + abs(xi - f) + abs(a - xi));
              upd(dp[fl ^ 1][b][a][yi][c], prev + abs(xi - f) + abs(b - xi));
              upd(dp[fl ^ 1][c][a][b][yi], prev + abs(xi - f) + abs(c - xi));
              upd(dp[fl ^ 1][yi][a][b][c], prev + abs(xi - f) + abs(yi - xi));
            }
          }
    fl ^= 1;
  }
  int ans = INF;
  for (int i = 1; i < 10; i++) ans = min(ans, dp[fl][i][0][0][0]);
  printf("%d\n", 2 * n + ans);
  return 0;
}
