#include <bits/stdc++.h>
using namespace std;
void OUT_TST(string s, istream_iterator<string> it) { cerr << s; }
template <typename T, typename... Args>
void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " ";
  OUT_TST(s, ++it, args...);
}
template <class T>
void rd(T& ret) {
  ret = 0;
  bool ok = 0, u = 0;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + (ret << 1) + c - '0', ok = 1;
    else if (c == '-')
      u = 1;
    else if (ok) {
      if (u) ret *= -1;
      return;
    }
  }
}
long long powmod(long long p, long long n, long long mod) {
  long long ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
  }
  return ret;
}
template <class T>
bool chmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int MX = 1 << 30;
int tcn, cn[10];
pair<int, int> an[2222];
int dp[2005][10][10][10][10], bn[10];
void gao(int a, int b, int c, int d) {
  cn[0] = a;
  cn[1] = b;
  cn[2] = c;
  cn[3] = d;
  tcn = 0;
  for (int i = (0); i < (5); i++)
    if (cn[i] == 0) {
      tcn = i;
      break;
    }
}
int calc(int first, int second, int p, int np) {
  int res, dis;
  chmin(second, tcn - 1);
  if (second < first) {
    if (np == 0) return 0;
    return abs(np - p);
  }
  dis = second - first + 1 + abs(cn[first] - p) + abs(cn[first] - cn[second]);
  if (np != 0) dis += abs(cn[second] - np);
  res = dis;
  dis = second - first + 1 + abs(cn[second] - p) + abs(cn[first] - cn[second]);
  if (np != 0) dis += abs(cn[first] - np);
  chmin(res, dis);
  return res;
}
void getState(int first, int second, int np) {
  for (int i = (0); i < (4); i++) bn[i] = cn[i];
  chmin(second, tcn - 1);
  for (int i = (first); i < (second + 1); i++) bn[i] = 0;
  for (int i = (0); i < (5); i++)
    if (bn[i] == 0) {
      assert(i <= 3);
      bn[i] = np;
      break;
    }
  sort(bn, bn + 4, greater<int>());
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d%d", &an[i].first, &an[i].second);
  for (int i = (0); i < (n + 1); i++)
    for (int j = (0); j < (10); j++)
      for (int k = (0); k < (10); k++)
        for (int a = (0); a < (10); a++)
          for (int b = (0); b < (10); b++) dp[i][j][k][a][b] = MX;
  dp[0][an[0].second][0][0][0] = abs(1 - an[0].first) + 1;
  int dis, p, np, nowd;
  for (int i = (0); i < (n - 1); i++)
    for (int j = (0); j < (10); j++)
      for (int k = (0); k < (j + 1); k++)
        for (int a = (0); a < (k + 1); a++)
          for (int b = (0); b < (a + 1); b++)
            if (dp[i][j][k][a][b] != MX) {
              gao(j, k, a, b);
              p = an[i].first;
              np = an[i + 1].first;
              nowd = dp[i][j][k][a][b];
              for (int first = (0); first < (tcn); first++)
                for (int second = (first); second < (tcn); second++) {
                  dis = calc(first, second, p, np) + 1;
                  getState(first, second, an[i + 1].second);
                  chmin(dp[i + 1][bn[0]][bn[1]][bn[2]][bn[3]], nowd + dis);
                }
              if (b == 0) {
                dis = abs(an[i].first - an[i + 1].first) + 1;
                getState(1, 0, an[i + 1].second);
                chmin(dp[i + 1][bn[0]][bn[1]][bn[2]][bn[3]], nowd + dis);
              }
            }
  int ans = MX;
  for (int a = (0); a < (10); a++)
    for (int b = (0); b < (10); b++)
      for (int c = (0); c < (10); c++)
        for (int d = (0); d < (10); d++)
          if (dp[n - 1][a][b][c][d] != MX) {
            nowd = dp[n - 1][a][b][c][d];
            gao(a, b, c, d);
            dis = calc(0, tcn - 1, an[n - 1].first, 0);
            chmin(ans, nowd + dis);
          }
  printf("%d\n", ans);
  return 0;
}
