#include <bits/stdc++.h>
using namespace std;
const int N = 500505;
const int mod = 1e9 + 7;
int n, a[N], b[N];
struct state {
  int i1, i2, i3, i4;
};
int g[10][10][10][10];
state get_state[10001];
int dp[2002][10][715];
int q[2002 * 10 * 715 * 3];
int states;
vector<int> Q;
int get_st(int i1, int i2, int i3, int i4) {
  Q = {i1, i2, i3, i4};
  sort(Q.begin(), Q.end());
  return g[Q[0]][Q[1]][Q[2]][Q[3]];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  b[0] = 0;
  a[0] = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
  }
  a[n + 1] = -1;
  b[n + 1] = 0;
  for (int i1 = 0; i1 < 10; ++i1)
    for (int i2 = i1; i2 < 10; ++i2)
      for (int i3 = i2; i3 < 10; ++i3)
        for (int i4 = i3; i4 < 10; ++i4) {
          g[i1][i2][i3][i4] = states;
          get_state[states] = {i1, i2, i3, i4};
          states++;
        }
  for (int p = 0; p <= n + 1; ++p) {
    for (int floor = 1; floor < 10; ++floor)
      for (int i = 0; i < states; ++i) dp[p][floor][i] = -1;
  }
  dp[0][1][g[0][0][0][0]] = 0;
  int qs = 0, qt = 0;
  q[qt++] = 0;
  q[qt++] = 1;
  q[qt++] = g[0][0][0][0];
  int ans = 2e9;
  while (qs < qt) {
    int p = q[qs++];
    int floor = q[qs++];
    int st = q[qs++];
    if (p == n && st == 0) ans = min(ans, dp[p][floor][st]);
    state s = get_state[st];
    if (s.i1 == floor) {
      int new_state = get_st(0, s.i2, s.i3, s.i4);
      if (dp[p][floor][new_state] == -1) {
        dp[p][floor][new_state] = dp[p][floor][st] + 1;
        q[qt++] = p, q[qt++] = floor, q[qt++] = new_state;
      }
    }
    if (s.i2 == floor) {
      int new_state = get_st(s.i1, 0, s.i3, s.i4);
      if (dp[p][floor][new_state] == -1) {
        dp[p][floor][new_state] = dp[p][floor][st] + 1;
        q[qt++] = p, q[qt++] = floor, q[qt++] = new_state;
      }
    }
    if (s.i3 == floor) {
      int new_state = get_st(s.i1, s.i2, 0, s.i4);
      if (dp[p][floor][new_state] == -1) {
        dp[p][floor][new_state] = dp[p][floor][st] + 1;
        q[qt++] = p, q[qt++] = floor, q[qt++] = new_state;
      }
    }
    if (s.i4 == floor) {
      int new_state = get_st(s.i1, s.i2, s.i3, 0);
      if (dp[p][floor][new_state] == -1) {
        dp[p][floor][new_state] = dp[p][floor][st] + 1;
        q[qt++] = p, q[qt++] = floor, q[qt++] = new_state;
      }
    }
    if (a[p + 1] == floor && s.i1 == 0) {
      int new_state = get_st(b[p + 1], s.i2, s.i3, s.i4);
      if (dp[p + 1][floor][new_state] == -1) {
        dp[p + 1][floor][new_state] = dp[p][floor][st] + 1;
        q[qt++] = p + 1, q[qt++] = floor, q[qt++] = new_state;
      }
    }
    if (floor + 1 < 10 && dp[p][floor + 1][st] == -1) {
      dp[p][floor + 1][st] = dp[p][floor][st] + 1;
      q[qt++] = p, q[qt++] = floor + 1, q[qt++] = st;
    }
    if (floor > 1 && dp[p][floor - 1][st] == -1) {
      dp[p][floor - 1][st] = dp[p][floor][st] + 1;
      q[qt++] = p, q[qt++] = floor - 1, q[qt++] = st;
    }
  }
  cout << ans;
  return 0;
}
