#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int M = 1e9 + 7;
string to_string(int x) {
  stringstream second;
  second << x;
  return second.str();
}
int to_integer(string s) {
  stringstream second(s);
  int x;
  second >> x;
  return x;
}
int a[2005], b[2005], n;
int dp[2005][10][10][10][10][2];
int fun(int i, int x1, int x2, int x3, int x4, int y) {
  if (dp[i][x1][x2][x3][x4][y] != -1) return dp[i][x1][x2][x3][x4][y];
  int ans = inf;
  int c1 = i, c2 = x4, cur;
  if (y == 1) {
    cur = a[i];
    x4 = b[i];
    i++;
  } else {
    cur = x4;
    x4 = 0;
  }
  if (i > n && x1 == 0 && x2 == 0 && x3 == 0 && x4 == 0) return 0;
  if (x1 != 0) ans = min(ans, (1 + abs(cur - x1)) + fun(i, x2, x3, x4, x1, 0));
  if (x2 != 0) ans = min(ans, (1 + abs(cur - x2)) + fun(i, x1, x3, x4, x2, 0));
  if (x3 != 0) ans = min(ans, (1 + abs(cur - x3)) + fun(i, x1, x2, x4, x3, 0));
  if (x4 != 0) ans = min(ans, (1 + abs(cur - x4)) + fun(i, x1, x2, x3, x4, 0));
  if (x1 == 0 && i <= n)
    ans = min(ans, (1 + abs(cur - a[i])) + fun(i, x2, x3, x4, x1, 1));
  if (x2 == 0 && i <= n)
    ans = min(ans, (1 + abs(cur - a[i])) + fun(i, x1, x3, x4, x2, 1));
  if (x3 == 0 && i <= n)
    ans = min(ans, (1 + abs(cur - a[i])) + fun(i, x1, x2, x4, x3, 1));
  if (x4 == 0 && i <= n)
    ans = min(ans, (1 + abs(cur - a[i])) + fun(i, x1, x2, x3, x4, 1));
  return dp[c1][x1][x2][x3][c2][y] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  memset(dp, -1, sizeof dp);
  cout << fun(1, 0, 0, 0, 0, 1) + a[1] << "\n";
  return 0;
}
