#include <bits/stdc++.h>
using namespace std;
bool f[2005][10][720];
int a[10005], k[6], c, t, n;
pair<int, int> p[2005];
struct node {
  int x, y, z, w;
};
queue<node> q;
void dfs(int x) {
  if (x == 4) {
    a[c] = ++t;
    return;
  }
  for (int i = c % 10; i <= 9; ++i) {
    c = c * 10 + i;
    dfs(x + 1);
    c /= 10;
  }
}
int merge(int x, int y) {
  c = 1;
  while (x) k[c++] = x % 10, x /= 10;
  k[c] = 0;
  for (int i = 1; i <= c; ++i) {
    if (k[i] >= y) continue;
    for (int j = c; j > i; --j) k[j] = k[j - 1];
    k[i] = y;
    break;
  }
  x = 1, y = 0;
  for (int i = 1; i <= c; ++i) y += x * k[i], x *= 10;
  return y;
}
int del(int x, int y) {
  c = 0;
  while (x) k[++c] = x % 10, x /= 10;
  for (int i = 1; i <= c; ++i) {
    if (k[i] != y) continue;
    for (int j = i; j < c; ++j) k[j] = k[j + 1];
    --i, --c;
  }
  x = 1, y = 0;
  for (int i = 1; i <= c; ++i) y += x * k[i], x *= 10;
  return y;
}
void work(int x, int y, int z, int v) {
  int u, w = x;
  if (y > 1) {
    u = del(z, y - 1);
    while (u < 1111 && y - 1 == p[w + 1].first) u = merge(u, p[++w].second);
    if (!f[w][y - 1][a[u]]) {
      f[w][y - 1][a[u]] = 1;
      q.push((node){w, y - 1, u, v + 1});
    }
  }
  w = x;
  if (y < 9) {
    u = del(z, y + 1);
    while (u < 1111 && y + 1 == p[w + 1].first) u = merge(u, p[++w].second);
    if (!f[w][y + 1][a[u]]) {
      f[w][y + 1][a[u]] = 1;
      q.push((node){w, y + 1, u, v + 1});
    }
  }
}
int main() {
  int x, y, s;
  dfs(0);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    p[i] = make_pair(x, y);
  }
  node z;
  q.push((node){0, 0, 0, -1});
  f[0][0][1] = 1;
  while (!q.empty()) {
    z = q.front();
    q.pop();
    if (z.x == n && !z.z) {
      printf("%d\n", z.w + (n << 1));
      break;
    }
    work(z.x, z.y, z.z, z.w);
  }
  return 0;
}
