#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
vector<int> G, vec[N << 1];
map<vector<int>, int> id;
int n, a[N], b[N], trans[N][12], cost[N][12], f[N][1005][10], tot, flag[N],
    num[N][10];
void dfs(int u, int lim) {
  if (u == 10) {
    vec[++tot] = G;
    id[G] = tot;
    return;
  }
  for (int i = 0; i <= lim; i++) G[u] = i, dfs(u + 1, lim - i);
}
int get_trans(int x, int y) {
  vector<int> v = vec[x];
  v[y] = 0;
  return id[v];
}
int get_num(int x, int y) {
  vector<int> v = vec[x];
  v[y]++;
  return id[v];
}
int check(int x) {
  int sum = 0;
  for (int i = 0; i < vec[x].size(); i++) sum += vec[x][i];
  return (sum < 4);
}
int main() {
  G.resize(10);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
  dfs(1, 4);
  for (int i = 1; i <= tot; i++) {
    flag[i] = check(i);
    for (int j = 1; j <= 9; j++) num[i][j] = get_num(i, j);
    for (int j = 1; j <= 9; j++)
      trans[i][j] = get_trans(i, j), cost[i][j] = vec[i][j];
  }
  memset(f, 63, sizeof(f));
  f[1][1][1] = 0;
  for (int i = 1; i <= n + 1; i++)
    for (int j = tot; j >= 1; j--)
      for (int k = 1; k <= 9; k++)
        for (int l = 1; l <= 9; l++) {
          int cur = trans[j][l];
          if (l == a[i] && flag[cur]) {
            cur = num[cur][b[i]];
            f[i + 1][cur][l] =
                min(f[i + 1][cur][l], f[i][j][k] + abs(k - l) + cost[j][l] + 1);
          } else if (cur != j)
            f[i][cur][l] =
                min(f[i][cur][l], f[i][j][k] + cost[j][l] + abs(k - l));
        }
  int ans = 1e9;
  for (int i = 1; i <= 9; i++) ans = min(ans, f[n + 1][1][i]);
  printf("%d\n", ans);
  return 0;
}
