#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000, N = 300000;
int n, a[N + 5], lmax[N + 5], rmax[N + 5], lmin[N + 5], rmin[N + 5],
    cnt[2 * N + 5];
long long ans;
void solve(int l, int r) {
  if (l == r) {
    ans++;
    return;
  }
  int mi = (l + r) / 2;
  rmin[mi + 1] = rmax[mi + 1] = a[mi + 1];
  for (int i = mi + 2; i <= r; i++) {
    rmin[i] = min(rmin[i - 1], a[i]);
    rmax[i] = max(rmax[i - 1], a[i]);
  }
  lmin[mi] = lmax[mi] = a[mi];
  for (int i = mi - 1; i >= l; i--) {
    lmin[i] = min(lmin[i + 1], a[i]);
    lmax[i] = max(lmax[i + 1], a[i]);
  }
  for (int i = l; i <= mi; i++) {
    int t = lmax[i] - lmin[i] - mi + i;
    if (t <= r - mi && t > 0 && lmin[i] < rmin[t + mi] &&
        rmax[t + mi] < lmax[i])
      ans++;
  }
  for (int i = mi + 1; i <= r; i++) {
    int t = rmax[i] - rmin[i] + 1 - i + mi;
    if (t <= mi - l + 1 && t > 0 && rmin[i] < lmin[mi - t + 1] &&
        lmax[mi - t + 1] < rmax[i])
      ans++;
  }
  int j = r, k = r;
  for (int i = l; i <= mi; i++) {
    for (; k > mi && rmax[k] > lmax[i]; k--) cnt[k - rmax[k] + N]++;
    for (; j > k && rmin[j] < lmin[i]; j--) cnt[j - rmax[j] + N]--;
    ans += cnt[i - lmin[i] + N];
  }
  for (; j > k; j--) cnt[j - rmax[j] + N]--;
  j = r, k = r;
  for (int i = l; i <= mi; i++) {
    for (; k > mi && rmin[k] < lmin[i]; k--) cnt[k + rmin[k]]++;
    for (; j > k && rmax[j] > lmax[i]; j--) cnt[j + rmin[j]]--;
    ans += cnt[i + lmax[i]];
  }
  for (; j > k; j--) cnt[j + rmin[j]]--;
  solve(l, mi);
  solve(mi + 1, r);
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    a[x] = y;
  }
  solve(1, n);
  cout << ans << endl;
  return 0;
}
