#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
const int N = 310000;
int pre[N], nl[N], nr[N], val[N], pos[N], n;
long long solve(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  int mid = (l + r) >> 1;
  long long ans = solve(l, mid - 1) + solve(mid + 1, r);
  int vl = val[mid], vr = val[mid];
  for (int i = l; i <= r; i++) nl[i] = nr[i] = 0;
  nl[mid] = mid;
  nr[mid] = mid;
  for (int i = mid - 1; i >= l; i--) {
    nl[i] = nl[i + 1];
    nr[i] = nr[i + 1];
    while (vl - 1 >= val[i] && vl >= val[mid] - r + l - 1)
      vl--, nl[i] = min(nl[i], pos[vl]), nr[i] = max(nr[i], pos[vl]);
    while (vr + 1 <= val[i] && vr <= val[mid] + r - l + 1)
      vr++, nl[i] = min(nl[i], pos[vr]), nr[i] = max(nr[i], pos[vr]);
  }
  vl = val[mid];
  vr = val[mid];
  for (int i = mid + 1; i <= r; i++) {
    nl[i] = nl[i - 1];
    nr[i] = nr[i - 1];
    while (vl - 1 >= val[i] && vl >= val[mid] - r + l - 1)
      vl--, nl[i] = min(nl[i], pos[vl]), nr[i] = max(nr[i], pos[vl]);
    while (vr + 1 <= val[i] && vr <= val[mid] + r - l + 1)
      vr++, nl[i] = min(nl[i], pos[vr]), nr[i] = max(nr[i], pos[vr]);
  }
  for (int i = l; i <= r; i++) pre[i] = 0;
  for (int i = mid; i <= r; i++) pre[i] = pre[i - 1] + (nr[i] == i);
  int R = mid;
  for (int i = mid; i >= l; i--) {
    if (nl[i] != i) continue;
    while (R <= r && nl[R] >= i) R++;
    R--;
    if (R >= nr[i]) ans += (long long)(pre[R] - pre[nr[i] - 1]);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  int x, y;
  for (int i = 1; i <= n; i++) scanf("%d%d", &x, &y), val[x] = y, pos[y] = x;
  printf("%lld\n", solve(1, n));
}
