#include <bits/stdc++.h>
using namespace std;
const int N = 301005;
const int ZERO = 300010;
int a[N];
int Lmin[N], Lmax[N], Rmin[N], Rmax[N];
int cnt[N * 2];
long long solve(int l, int r) {
  if (l == r) return 1;
  int mid = (l + r) >> 1;
  long long res = solve(l, mid) + solve(mid + 1, r);
  Lmin[mid] = Lmax[mid] = a[mid];
  for (int i = mid - 1; i >= l; --i) {
    Lmin[i] = min(a[i], Lmin[i + 1]);
    Lmax[i] = max(a[i], Lmax[i + 1]);
  }
  Rmin[mid + 1] = Rmax[mid + 1] = a[mid + 1];
  for (int i = mid + 2; i <= r; ++i) {
    Rmin[i] = min(a[i], Rmin[i - 1]);
    Rmax[i] = max(a[i], Rmax[i - 1]);
  }
  for (int i = l; i <= mid; ++i) {
    int len = Lmax[i] - Lmin[i];
    int y = i + len;
    if (y > mid && y <= r && Rmin[y] > Lmin[i] && Rmax[y] < Lmax[i]) ++res;
  }
  for (int i = mid + 1; i <= r; ++i) {
    int len = Rmax[i] - Rmin[i];
    int x = i - len;
    if (x <= mid && x >= l && Lmin[x] > Rmin[i] && Lmax[x] < Rmax[i]) ++res;
  }
  for (int i = mid + 1, j = mid, k = mid; i <= r; ++i) {
    for (; j >= l && Lmin[j] > Rmin[i]; --j) ++cnt[j + Lmax[j]];
    for (; k >= l && Lmax[k] < Rmax[i]; --k) --cnt[k + Lmax[k]];
    if (j < k) res += cnt[i + Rmin[i]];
  }
  for (int i = l; i <= mid; ++i) cnt[i + Lmax[i]] = 0;
  for (int i = mid + 1, j = mid, k = mid; i <= r; ++i) {
    for (; j >= l && Lmax[j] < Rmax[i]; --j) ++cnt[Lmin[j] - j + ZERO];
    for (; k >= l && Lmin[k] > Rmin[i]; --k) --cnt[Lmin[k] - k + ZERO];
    if (j < k) res += cnt[Rmax[i] - i + ZERO];
  }
  for (int i = l; i <= mid; ++i) cnt[Lmin[i] - i + ZERO] = 0;
  return res;
}
int main() {
  int n;
  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;
}
