#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MAX = 2e3 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 1000000006;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 316;
int n, dp[MAX][9][716], x[MAX], y[MAX], rem[716][9], add[716][9], vis[10000],
    id, tmp;
int f(int nw, int pos, int mask) {
  if (nw > n && mask == 1) return 0;
  if (dp[nw][pos][mask] != -1) return dp[nw][pos][mask];
  int ret = MOD, msk;
  if (nw <= n && add[mask][y[nw]] != -1)
    ret = f(nw + 1, x[nw], add[mask][y[nw]]) + abs(x[nw] - pos);
  for (int i = 0; i <= 8; ++i) {
    msk = rem[mask][i];
    if (msk != mask) ret = min(ret, f(nw, i, msk) + abs(pos - i));
  }
  return dp[nw][pos][mask] = ret;
}
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int nw, nx;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i], --x[i], --y[i];
  x[n + 1] = -1;
  for (int a = 0; a <= 9; ++a)
    for (int b = 0; b <= 9; ++b)
      for (int c = 0; c <= 9; ++c)
        for (int d = 0; d <= 9; ++d) {
          v.clear();
          v.push_back(a), v.push_back(b), v.push_back(c), v.push_back(d);
          sort(v.begin(), v.end());
          nw = v[0] * 1000 + v[1] * 100 + v[2] * 10 + v[3];
          if (!vis[nw]) vis[nw] = ++id;
          nw = vis[nw];
          v.clear();
          if (add[nw][0]) continue;
          for (int k = 1; k <= 9; ++k) {
            v.push_back(a), v.push_back(b), v.push_back(c), v.push_back(d);
            for (auto &i : v)
              if (i == k) i = 0;
            sort(v.begin(), v.end());
            nx = v[0] * 1000 + v[1] * 100 + v[2] * 10 + v[3];
            if (!vis[nx]) vis[nx] = ++id;
            nx = vis[nx];
            rem[nw][k - 1] = nx;
            v.clear();
          }
          for (int k = 1; k <= 9; ++k) {
            v.push_back(a), v.push_back(b), v.push_back(c), v.push_back(d);
            sort(v.begin(), v.end());
            if (v[0])
              add[nw][k - 1] = -1;
            else {
              v[0] = k;
              sort(v.begin(), v.end());
              nx = v[0] * 1000 + v[1] * 100 + v[2] * 10 + v[3];
              if (!vis[nx]) vis[nx] = ++id;
              nx = vis[nx];
              add[nw][k - 1] = nx;
            }
            v.clear();
          }
        }
  memset(dp, -1, sizeof dp);
  cout << f(1, 0, 1) + n + n << '\n';
  return 0;
}
