#include <bits/stdc++.h>
using namespace std;
short dp[2001][5][10][10][10][10], n;
pair<short, short> ar[2010];
short rec(short p, short id, short d1, short d2, short d3, short d4) {
  short c1, c2, c3, c4, cp;
  if (id == 0) cp = ar[p].first;
  if (id == 1) cp = d1;
  if (id == 2) cp = d2;
  if (id == 3) cp = d3;
  if (id == 4) cp = d4;
  if (cp == d1)
    c1 = 0;
  else
    c1 = d1;
  if (cp == d2)
    c2 = 0;
  else
    c2 = d2;
  if (cp == d3)
    c3 = 0;
  else
    c3 = d3;
  if (cp == d4)
    c4 = 0;
  else
    c4 = d4;
  if (p == n && !c1 && !c2 && !c3 && !c4) return 0;
  short &temp = dp[p][id][d1][d2][d3][d4];
  if (temp != -1) return temp;
  temp = 32767;
  if (!(c1 && c2 && c3 && c4) && p < n) {
    if (c1 == 0)
      temp = abs(ar[p + 1].first - cp) +
             rec(p + 1, 0, ar[p + 1].second, c2, c3, c4);
    else if (c2 == 0)
      temp = abs(ar[p + 1].first - cp) +
             rec(p + 1, 0, c1, ar[p + 1].second, c3, c4);
    else if (c3 == 0)
      temp = abs(ar[p + 1].first - cp) +
             rec(p + 1, 0, c1, c2, ar[p + 1].second, c4);
    else
      temp = abs(ar[p + 1].first - cp) +
             rec(p + 1, 0, c1, c2, c3, ar[p + 1].second);
  }
  if (c1) {
    short ok = abs(cp - c1) + rec(p, 1, c1, c2, c3, c4);
    temp = min(temp, ok);
  }
  if (c2) {
    short ok = abs(cp - c2) + rec(p, 2, c1, c2, c3, c4);
    temp = min(temp, ok);
  }
  if (c3) {
    short ok = abs(cp - c3) + rec(p, 3, c1, c2, c3, c4);
    temp = min(temp, ok);
  }
  if (c4) {
    short ok = abs(cp - c4) + rec(p, 4, c1, c2, c3, c4);
    temp = min(temp, ok);
  }
  return temp;
}
int main() {
  ios::sync_with_stdio(false);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (short i = 1; i <= n; i++) cin >> ar[i].first >> ar[i].second;
  ar[0].first = 1;
  cout << rec(0, 0, 0, 0, 0, 0) + n * 2 << endl;
  return 0;
}
