#include <bits/stdc++.h>
using namespace std;
int dp[2][10][10][10][10][10];
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  for (int i = 0; i <= 1; ++i) {
    for (int pos = 0; pos < 10; ++pos) {
      for (int i1 = 0; i1 < 10; ++i1) {
        for (int i2 = 0; i2 < 10; ++i2) {
          for (int i3 = 0; i3 < 10; ++i3) {
            for (int i4 = 0; i4 < 10; ++i4) {
              dp[i][pos][i1][i2][i3][i4] = 10000000;
            }
          }
        }
      }
    }
  }
  dp[1][1][0][0][0][0] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int i1 = 9; i1 >= 0; --i1) {
      for (int i2 = 9; i2 >= 0; --i2) {
        for (int i3 = 9; i3 >= 0; --i3) {
          for (int i4 = 9; i4 >= 0; --i4) {
            for (int pos = 1; pos < 10; ++pos) {
              dp[0][pos][i1][i2][i3][i4] = dp[1][pos][i1][i2][i3][i4];
              dp[1][pos][i1][i2][i3][i4] = 10000000;
            }
          }
        }
      }
    }
    for (int i1 = 9; i1 >= 0; --i1) {
      for (int i2 = 9; i2 >= 0; --i2) {
        for (int i3 = 9; i3 >= 0; --i3) {
          for (int i4 = 9; i4 >= 0; --i4) {
            for (int pos = 1; pos < 10; ++pos) {
              if (i1 != 0) {
                dp[0][i1][0][i2][i3][i4] =
                    min(dp[0][i1][0][i2][i3][i4],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - i1));
              } else if (i < n) {
                dp[1][a[i]][b[i]][i2][i3][i4] =
                    min(dp[1][a[i]][b[i]][i2][i3][i4],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - a[i]));
              }
              if (i2 != 0) {
                dp[0][i2][i1][0][i3][i4] =
                    min(dp[0][i2][i1][0][i3][i4],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - i2));
              } else if (i < n) {
                dp[1][a[i]][i1][b[i]][i3][i4] =
                    min(dp[1][a[i]][i1][b[i]][i3][i4],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - a[i]));
              }
              if (i3 != 0) {
                dp[0][i3][i1][i2][0][i4] =
                    min(dp[0][i3][i1][i2][0][i4],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - i3));
              } else if (i < n) {
                dp[1][a[i]][i1][i2][b[i]][i4] =
                    min(dp[1][a[i]][i1][i2][b[i]][i4],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - a[i]));
              }
              if (i4 != 0) {
                dp[0][i4][i1][i2][i3][0] =
                    min(dp[0][i4][i1][i2][i3][0],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - i4));
              } else if (i < n) {
                dp[1][a[i]][i1][i2][i3][b[i]] =
                    min(dp[1][a[i]][i1][i2][i3][b[i]],
                        dp[0][pos][i1][i2][i3][i4] + 1 + abs(pos - a[i]));
              }
            }
          }
        }
      }
    }
  }
  int ans = INT_MAX;
  for (int i = 1; i < 10; ++i) {
    ans = min(ans, dp[0][i][0][0][0][0]);
  }
  cout << ans;
}
