#include <bits/stdc++.h>
using namespace std;
const long long LINF = (long long)1e18;
const int INF = (int)1e9 + 7;
const int N = (int)1e6 + 7;
const double EPS = (double)1e-9;
const double PI = (double)3.14159265359;
const int MODULO[6] = {INF,        1000019677, 1000019393,
                       1000007521, 1000024073, 1000009667};
const int PF[5] = {77, 31, 98, 45, 67};
const int nx[4] = {0, 0, 1, -1};
const int ny[4] = {1, -1, 0, 0};
inline bool eq(const long double &a, const long double &b) {
  return fabs(a - b) < EPS;
}
int n;
map<pair<int, int>, int> second;
set<int> st;
pair<int, int> p[N];
int under(pair<int, int> x) {
  int cnt = 0;
  for (int a = -1; a < 2; a++) {
    pair<int, int> pr = {x.first + a, x.second - 1};
    cnt += (second[pr] != 0);
  }
  return cnt;
}
bool ok(pair<int, int> x) {
  for (int a = -1; a < 2; a++) {
    pair<int, int> pr = {x.first + a, x.second + 1};
    if (second[pr] && under(pr) == 1) return false;
  }
  return true;
}
int main() {
  srand(time(NULL));
  scanf("%d", &n);
  ;
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i].first);
    ;
    scanf("%d", &p[i].second);
    ;
    second[p[i]] = i + 1;
  }
  for (int i = 0; i < n; i++)
    if (ok(p[i])) st.insert(i);
  long long res = 0ll;
  for (int i = 0; i < n; i++) {
    pair<int, int> cur;
    assert(!st.empty());
    if (i % 2 == 0) {
      cur = p[*st.rbegin()];
      st.erase(*st.rbegin());
    } else {
      cur = p[*st.begin()];
      st.erase(st.begin());
    }
    res = (res * n + second[cur] - 1) % (INF + 2);
    second[cur] = 0;
    for (int a = -1; a < 2; a++) {
      pair<int, int> pr = {cur.first + a, cur.second + 1};
      int id = second[pr] - 1;
      if (id >= 0 && ok(pr)) st.insert(id);
    }
    for (int a = -1; a < 2; a++) {
      pair<int, int> pr = {cur.first + a, cur.second - 1};
      int id = second[pr] - 1;
      if (id >= 0 && ok(pr)) st.insert(id);
    }
    for (int a = -2; a < 3; a++) {
      pair<int, int> pr = {cur.first + a, cur.second};
      int id = second[pr] - 1;
      if (id < 0 || ok(pr)) continue;
      if (st.find(id) != st.end()) st.erase(st.find(id));
    }
  }
  printf("%d", (int)res);
  return 0;
}
