#include <bits/stdc++.h>
using namespace std;
int N, A[2004], B[2004], D[2000][10][1000];
int f(int idx, int floor, int person) {
  int a, b;
  if (idx == N) {
    if (person == 0) return 0;
    int lo, hi, ret;
    lo = hi = person % 10;
    ret = 1;
    for (a = person / 10; a; a /= 10, ret++) {
      b = a % 10;
      if (lo > b) lo = b;
      if (hi < b) hi = b;
    }
    if (floor < lo) {
      ret += hi - floor;
    } else if (floor > hi) {
      ret += floor - lo;
    } else {
      ret += hi - lo;
      ret += min(hi - floor, floor - lo);
    }
    return ret;
  }
  int &ret = D[idx][floor][person];
  if (ret != -1) return ret;
  if (!person) {
    a = A[idx];
    b = B[idx];
    ret = f(idx + 1, a, b) + abs(floor - a) + 1;
  } else {
    int ret1;
    a = person % 10;
    ret = f(idx, a, person / 10) + abs(floor - a) + 1;
    if (person > 10) {
      b = (person / 10) % 10;
      ret1 = f(idx, b, (person / 100) * 10 + a) + abs(floor - b) + 1;
      if (ret > ret1) ret = ret1;
    }
    if (person > 100) {
      b = person / 100;
      ret1 = f(idx, b, person - b * 100) + abs(floor - b) + 1;
      if (ret > ret1) ret = ret1;
    }
    if (person > 100) {
      int ret2, xx, c;
      person += B[idx] * 1000;
      a = A[idx];
      xx = abs(floor - a) + 1;
      floor = a;
      a = person % 10;
      ret1 = f(idx + 1, a, person / 10) + abs(floor - a) + 1;
      b = (person / 10) % 10;
      ret2 = f(idx + 1, b, (person / 100) * 10 + a) + abs(floor - b) + 1;
      if (ret1 > ret2) ret1 = ret2;
      c = (person / 100) % 10;
      ret2 = f(idx + 1, c, (person / 1000) * 100 + b * 10 + a) +
             abs(floor - c) + 1;
      if (ret1 > ret2) ret1 = ret2;
      b = person / 1000;
      ret2 = f(idx + 1, b, person - b * 1000) + abs(floor - b) + 1;
      if (ret1 > ret2) ret1 = ret2;
      ret1 += xx;
    } else {
      person = person * 10 + B[idx];
      a = A[idx];
      ret1 = f(idx + 1, a, person) + abs(floor - a) + 1;
    }
    if (ret > ret1) ret = ret1;
  }
  return ret;
}
int main() {
  int i, j, k;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  for (i = 0; i < N; i++)
    for (j = 1; j <= 9; j++)
      for (k = 0; k <= 999; k++) D[i][j][k] = -1;
  cout << f(0, 1, 0);
}
