#include <bits/stdc++.h>
using namespace std;
int ok[2001][10][1000];
map<vector<int>, int> mp;
vector<int> state[1000];
int pre, n, a[2001][2];
struct elevator {
  int curFloor;
  int curState;
  int peopleOut;
};
vector<elevator> ruler;
int bfs(int t) {
  int cur = ruler.size();
  for (int i = pre; i < cur; i++) {
    vector<int> curPeople;
    curPeople.clear();
    for (int e = 0; e < state[ruler[i].curState].size(); e++) {
      curPeople.push_back(state[ruler[i].curState][e]);
    }
    int handled = ruler[i].peopleOut + (curPeople).size();
    if (handled == n && curPeople.size() == 0) {
      return t;
    }
    for (int e = 0; e < (curPeople).size(); e++) {
      if ((curPeople)[e] == ruler[i].curFloor) {
        vector<int> temp;
        temp.clear();
        for (int f = 0; f < (curPeople).size(); f++) {
          if (f != e) {
            temp.push_back((curPeople)[f]);
          }
        }
        sort(temp.begin(), temp.end());
        int mping = mp[temp];
        if (ok[ruler[i].peopleOut + 1][ruler[i].curFloor][mping] == 0) {
          ok[ruler[i].peopleOut + 1][ruler[i].curFloor][mping] = 1;
          struct elevator nxt = {ruler[i].curFloor, mping,
                                 ruler[i].peopleOut + 1};
          ruler.push_back(nxt);
        }
      }
    }
    if (curPeople.size() != 4) {
      if (a[handled + 1][0] == ruler[i].curFloor) {
        vector<int> temp;
        temp.clear();
        for (int f = 0; f < (curPeople).size(); f++) {
          temp.push_back((curPeople)[f]);
        }
        temp.push_back(a[handled + 1][1]);
        sort(temp.begin(), temp.end());
        int mping = mp[temp];
        if (ok[ruler[i].peopleOut][ruler[i].curFloor][mping] == 0) {
          ok[ruler[i].peopleOut][ruler[i].curFloor][mping] = 1;
          struct elevator nxt = {ruler[i].curFloor, mping, ruler[i].peopleOut};
          ruler.push_back(nxt);
        }
      }
    }
    if (ruler[i].curFloor != 9) {
      if (ok[ruler[i].peopleOut][ruler[i].curFloor + 1][ruler[i].curState] ==
          0) {
        ok[ruler[i].peopleOut][ruler[i].curFloor + 1][ruler[i].curState] = 1;
        struct elevator nxt = {ruler[i].curFloor + 1, ruler[i].curState,
                               ruler[i].peopleOut};
        ruler.push_back(nxt);
      }
    }
    if (ruler[i].curFloor != 1) {
      if (ok[ruler[i].peopleOut][ruler[i].curFloor - 1][ruler[i].curState] ==
          0) {
        ok[ruler[i].peopleOut][ruler[i].curFloor - 1][ruler[i].curState] = 1;
        struct elevator nxt = {ruler[i].curFloor - 1, ruler[i].curState,
                               ruler[i].peopleOut};
        ruler.push_back(nxt);
      }
    }
  }
  pre = cur;
  return bfs(t + 1);
}
int kq = 0;
vector<int> got;
void est(int k, int v) {
  if (k == 10) {
    kq++;
    for (int i = 0; i < 9; i++) {
      for (int e = 0; e < got[i]; e++) {
        state[kq].push_back(i + 1);
      }
    }
    mp[state[kq]] = kq;
  }
  if (k == 10) return;
  for (int i = 0; i <= v; i++) {
    got.push_back(i);
    est(k + 1, v - i);
    got.pop_back();
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i][0];
    cin >> a[i][1];
  }
  est(1, 4);
  pre = 0;
  struct elevator nxt = {1, 1, 0};
  ruler.push_back(nxt);
  cout << bfs(0) << '\n';
}
