#include <bits/stdc++.h>
using namespace std;
template <typename T>
auto operator<<(ostream &out, T &container)
    -> decltype(container.begin(), container.end(), out) {
  bool first = true;
  out << "[";
  for (auto it = container.begin(); it != container.end(); ++it) {
    if (!first) out << ", ";
    out << *it;
    first = false;
  }
  return out << "]";
}
int dp[2000][9][10][10][10][2];
int n;
int a[2000], c[2000];
void calc(int l, int t1l, int t1r, int t2l, int t2r, int t3l, int t3r, int b) {
  for (int p = 0; p < 9; ++p) {
    for (int t1 = t1l; t1 <= t1r; ++t1) {
      for (int t2 = t2l; t2 <= t2r; ++t2) {
        for (int t3 = t3l; t3 <= t3r; ++t3) {
          int &cur = dp[l][p][t1][t2][t3][b];
          if (l < n - 1) {
            if (b == 0) {
              dp[l + 1][a[l + 1]][t1][t2][t3][1] =
                  min(dp[l + 1][a[l + 1]][t1][t2][t3][1],
                      cur + abs(p - a[l + 1]) + 1);
            } else if (t1 == 9) {
              dp[l + 1][a[l + 1]][c[l]][t2][t3][1] =
                  min(dp[l + 1][a[l + 1]][c[l]][t2][t3][1],
                      cur + abs(p - a[l + 1]) + 1);
            } else if (t2 == 9) {
              dp[l + 1][a[l + 1]][t1][c[l]][t3][1] =
                  min(dp[l + 1][a[l + 1]][t1][c[l]][t3][1],
                      cur + abs(p - a[l + 1]) + 1);
            } else if (t3 == 9) {
              dp[l + 1][a[l + 1]][t1][t2][c[l]][1] =
                  min(dp[l + 1][a[l + 1]][t1][t2][c[l]][1],
                      cur + abs(p - a[l + 1]) + 1);
            }
          }
          if (b == 1) {
            dp[l][c[l]][t1][t2][t3][0] =
                min(dp[l][c[l]][t1][t2][t3][0], cur + abs(p - c[l]) + 1);
          }
          if (t1 != 9) {
            dp[l][t1][9][t2][t3][b] =
                min(dp[l][t1][9][t2][t3][b], cur + abs(p - t1) + 1);
          }
          if (t2 != 9) {
            dp[l][t2][t1][9][t3][b] =
                min(dp[l][t2][t1][9][t3][b], cur + abs(p - t2) + 1);
          }
          if (t3 != 9) {
            dp[l][t3][t1][t2][9][b] =
                min(dp[l][t3][t1][t2][9][b], cur + abs(p - t3) + 1);
          }
        }
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> c[i];
    a[i]--;
    c[i]--;
  }
  for (int x1 = 0; x1 < n; ++x1)
    for (int x2 = 0; x2 < 9; ++x2)
      for (int x3 = 0; x3 < 10; ++x3)
        for (int x4 = 0; x4 < 10; ++x4)
          for (int x5 = 0; x5 < 10; ++x5)
            for (int x6 = 0; x6 < 2; ++x6) dp[x1][x2][x3][x4][x5][x6] = 1e9;
  dp[0][a[0]][9][9][9][1] = a[0] + 1;
  for (int l = 0; l < n; ++l) {
    calc(l, 0, 8, 0, 8, 0, 8, 1);
    calc(l, 0, 8, 0, 8, 0, 8, 0);
    calc(l, 0, 8, 0, 8, 9, 9, 1);
    calc(l, 0, 8, 9, 9, 0, 8, 1);
    calc(l, 9, 9, 0, 8, 0, 8, 1);
    calc(l, 0, 8, 0, 8, 9, 9, 0);
    calc(l, 0, 8, 9, 9, 0, 8, 0);
    calc(l, 9, 9, 0, 8, 0, 8, 0);
    calc(l, 0, 8, 9, 9, 9, 9, 1);
    calc(l, 9, 9, 0, 8, 9, 9, 1);
    calc(l, 9, 9, 9, 9, 0, 8, 1);
    calc(l, 0, 8, 9, 9, 9, 9, 0);
    calc(l, 9, 9, 0, 8, 9, 9, 0);
    calc(l, 9, 9, 9, 9, 0, 8, 0);
    calc(l, 9, 9, 9, 9, 9, 9, 1);
    calc(l, 9, 9, 9, 9, 9, 9, 0);
  }
  int res = 1e9;
  for (int i = 0; i < 9; ++i) res = min(res, dp[n - 1][i][9][9][9][0]);
  cout << res << "\n";
}
