#include <bits/stdc++.h>
using namespace std;
int TAX[600000 + 10];
int A[600000 + 10], Lmax[600000 + 10], Lmin[600000 + 10], Rmax[600000 + 10],
    Rmin[600000 + 10];
int *tax = TAX + 300005;
int n;
long long Calc(int l, int r, int m) {
  long long ret = 0;
  Lmax[m] = Lmin[m] = A[m];
  Rmax[m + 1] = Rmin[m + 1] = A[m + 1];
  for (int i = m - 1; i >= l; i--) {
    Lmax[i] = max(Lmax[i + 1], A[i]);
    Lmin[i] = min(Lmin[i + 1], A[i]);
  }
  for (int i = m + 2; i <= r; i++) {
    Rmax[i] = max(Rmax[i - 1], A[i]);
    Rmin[i] = min(Rmin[i - 1], A[i]);
  }
  for (int i = l; i <= m; i++) {
    int j = i + Lmax[i] - Lmin[i];
    if (j > m && Rmax[j] < Lmax[i] && Rmin[j] > Lmin[i]) ret++;
  }
  int p = m + 1, q = m + 1;
  tax[Rmax[q] - q]++;
  while (q < r && Rmin[q + 1] > Lmin[l]) q++, tax[Rmax[q] - q]++;
  while (p <= r && Rmax[p] < Lmax[l]) tax[Rmax[p] - p]--, p++;
  for (int i = l; i <= m; i++) {
    while (p > m + 1 && Rmax[p - 1] > Lmax[i]) p--, tax[Rmax[p] - p]++;
    while (q > m && Rmin[q] < Lmin[i]) tax[Rmax[q] - q]--, q--;
    ret += max(tax[Lmin[i] - i], 0);
  }
  for (int i = m + 1; i <= r; i++) tax[Rmax[i] - i] = 0;
  return ret;
}
long long Solve(int l, int r) {
  if (l == r) return 1ll;
  int mid = (l + r) / 2;
  long long ret = Solve(l, mid) + Solve(mid + 1, r);
  ret += Calc(l, r, mid);
  reverse(A + l, A + r + 1);
  if ((r - l + 1) % 2) mid--;
  ret += Calc(l, r, mid);
  reverse(A + l, A + r + 1);
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    A[x] = y;
  }
  printf("%I64d\n", Solve(1, n));
  return 0;
}
