#include <bits/stdc++.h>
using namespace std;
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int n;
pair<int, int> ara[2002];
int dp[2002][10][10][10][10];
int func(int pos, int cur, int m1, int m2, int m3) {
  int om1 = m1;
  int om2 = m2;
  int om3 = m3;
  int yo = 0;
  if (m1 == cur) {
    m1 = 0;
    yo++;
  }
  if (m2 == cur) {
    m2 = 0;
    yo++;
  }
  if (m3 == cur) {
    m3 = 0;
    yo++;
  }
  if (pos == n && m1 == 0 && m2 == 0 && m3 == 0) {
    return yo;
  }
  if (dp[pos][cur][om1][om2][om3] != -1) {
    return dp[pos][cur][om1][om2][om3];
  }
  int ans = 1000000000;
  if (m1) {
    ans = min(ans, yo + abs(cur - m1) + func(pos, m1, m1, m2, m3));
  }
  if (m2) {
    ans = min(ans, yo + abs(cur - m2) + func(pos, m2, m1, m2, m3));
  }
  if (m3) {
    ans = min(ans, yo + abs(cur - m3) + func(pos, m3, m1, m2, m3));
  }
  if (pos != n) {
    yo++;
    if (m1 == 0) {
      ans =
          min(ans, yo + abs(cur - ara[pos].first) +
                       func(pos + 1, ara[pos].first, ara[pos].second, m2, m3));
    } else if (m2 == 0) {
      ans =
          min(ans, yo + abs(cur - ara[pos].first) +
                       func(pos + 1, ara[pos].first, m1, ara[pos].second, m3));
    } else if (m3 == 0) {
      ans =
          min(ans, yo + abs(cur - ara[pos].first) +
                       func(pos + 1, ara[pos].first, m1, m2, ara[pos].second));
    }
    if (m1 != 0 && m2 != 0 && m3 != 0) {
      yo += abs(cur - ara[pos].first);
      yo++;
      ans = min(ans, yo + abs(ara[pos].first - ara[pos].second) +
                         func(pos + 1, ara[pos].second, m1, m2, m3));
      ans = min(ans, yo + abs(ara[pos].first - m1) +
                         func(pos + 1, m1, ara[pos].second, m2, m3));
      ans = min(ans, yo + abs(ara[pos].first - m2) +
                         func(pos + 1, m2, m1, ara[pos].second, m3));
      ans = min(ans, yo + abs(ara[pos].first - m3) +
                         func(pos + 1, m3, m1, m2, ara[pos].second));
    }
  }
  return dp[pos][cur][om1][om2][om3] = ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    cin >> ara[i].first >> ara[i].second;
  }
  memset(dp, -1, sizeof(dp));
  cout << func(0, 1, 0, 0, 0) << "\n";
  return 0;
}
