#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using ld = long double;
mt19937 rnd(time(nullptr));
const int inf = 1e9;
const int MAX_N = 2000;
bool dist[MAX_N + 1][10][10][10][10][10];
struct Value {
  int counter, x1, x2, x3, x4, floor, value;
};
Value GetNext(int counter, int x1, int x2, int x3, int x4, int floor,
              int value);
void BFS(vector<pair<int, int>>& data);
inline void Solve() {
  int n = 0;
  cin >> n;
  vector<pair<int, int>> data(n);
  for (auto& it : data) {
    cin >> it.first >> it.second;
  }
  BFS(data);
}
Value GetNext(int counter, int x1, int x2, int x3, int x4, int floor,
              int value) {
  vector<int> buffer({x1, x2, x3, x4});
  sort(buffer.begin(), buffer.end());
  x1 = buffer[0];
  x2 = buffer[1];
  x3 = buffer[2];
  x4 = buffer[3];
  return Value({counter, x1, x2, x3, x4, floor, value});
}
void BFS(vector<pair<int, int>>& data) {
  queue<Value> q;
  q.push({0, 0, 0, 0, 0, 1, 0});
  dist[0][0][0][0][0][1] = 0;
  int result = inf;
  while (!q.empty()) {
    int counter = q.front().counter, x1 = q.front().x1, x2 = q.front().x2,
        x3 = q.front().x3, x4 = q.front().x4, floor = q.front().floor,
        value = q.front().value;
    q.pop();
    if ((counter == data.size()) && (x1 == 0) && (x2 == 0) && (x3 == 0) &&
        (x4 == 0))
      result = min(result, value);
    if (floor < 9) {
      Value tmp = GetNext(counter, x1, x2, x3, x4, floor + 1, value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
    if (floor > 1) {
      Value tmp = GetNext(counter, x1, x2, x3, x4, floor - 1, value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
    if (x1 == floor) {
      Value tmp = GetNext(counter, 0, x2, x3, x4, floor, value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
    if (x2 == floor) {
      Value tmp = GetNext(counter, x1, 0, x3, x4, floor, value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
    if (x3 == floor) {
      Value tmp = GetNext(counter, x1, x2, 0, x4, floor, value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
    if (x4 == floor) {
      Value tmp = GetNext(counter, x1, x2, x3, 0, floor, value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
    if ((counter < data.size()) && (data[counter].first == floor) &&
        (x1 == 0)) {
      Value tmp = GetNext(counter + 1, data[counter].second, x2, x3, x4, floor,
                          value + 1);
      if (!dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor]) {
        dist[tmp.counter][tmp.x1][tmp.x2][tmp.x3][tmp.x4][tmp.floor] = true;
        q.push(tmp);
      }
    }
  }
  cout << result;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(20);
  Solve();
  return 0;
}
