#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6e5 + 7;
int mx[MAXN / 2], mi[MAXN / 2], s[MAXN], a[MAXN / 2];
long long solve(int l, int r) {
  if (l == r) return 1;
  int mid = l + r >> 1;
  mx[mid] = mi[mid] = a[mid];
  mx[mid + 1] = mi[mid + 1] = a[mid + 1];
  for (int i = mid - 1; i >= l; i--)
    mx[i] = max(a[i], mx[i + 1]), mi[i] = min(a[i], mi[i + 1]);
  for (int i = mid + 2; i <= r; i++)
    mx[i] = max(a[i], mx[i - 1]), mi[i] = min(a[i], mi[i - 1]);
  long long res = 0;
  for (int i = mid; i >= l; i--) {
    int ta = mx[i] - mi[i] + i;
    if (ta <= r && ta > mid && mx[ta] < mx[i] && mi[ta] > mi[i]) res++;
  }
  for (int i = mid + 1; i <= r; i++) {
    int ta = i - mx[i] + mi[i];
    if (l <= ta && ta <= mid && mx[ta] < mx[i] && mi[ta] > mi[i]) res++;
  }
  int ri = mid + 1, li = mid + 1;
  for (int i = mid; i >= l; i--) {
    while (ri <= r && mx[ri] < mx[i]) s[mi[ri] + ri]++, ri++;
    while (li < ri && mi[li] > mi[i]) s[mi[li] + li]--, li++;
    res += s[mx[i] + i];
  }
  while (li < ri) s[mi[li] + li]--, li++;
  ri = mid + 1, li = mid + 1;
  for (int i = mid; i >= l; i--) {
    while (ri <= r && mi[ri] > mi[i]) s[mx[ri] - ri + r]++, ri++;
    while (li < ri && mx[li] < mx[i]) s[mx[li] - li + r]--, li++;
    res += s[mi[i] - i + r];
  }
  while (li < ri) s[mx[li] - li + r]--, li++;
  return solve(l, mid) + solve(mid + 1, r) + res;
}
int main() {
  int n, ta, tb;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &ta, &tb);
    a[ta] = tb;
  }
  printf("%lld\n", solve(1, n));
  return 0;
}
