#include <bits/stdc++.h>
using namespace std;
const int Maxn = 300005;
inline int read() {
  char c;
  int rec = 0;
  while ((c = getchar()) < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9') rec = rec * 10 + c - '0', c = getchar();
  return rec;
}
int n, a[Maxn];
long long ans;
int mn[Maxn], mx[Maxn], s[Maxn << 1];
inline void CDQ(int L, int R) {
  if (L == R) {
    ++ans;
    return;
  }
  int mid = (L + R) >> 1, p, q;
  CDQ(L, mid);
  CDQ(mid + 1, R);
  mn[mid] = mx[mid] = a[mid];
  mn[mid + 1] = mx[mid + 1] = a[mid + 1];
  for (int i = mid - 1; i >= L; --i)
    mn[i] = min(a[i], mn[i + 1]), mx[i] = max(a[i], mx[i + 1]);
  for (int i = mid + 2; i <= R; ++i)
    mn[i] = min(a[i], mn[i - 1]), mx[i] = max(a[i], mx[i - 1]);
  for (int i = mid; i >= L; --i) {
    p = mx[i] - mn[i] + i;
    if (p > mid && p <= R && mx[p] < mx[i] && mn[p] > mn[i]) ++ans;
  }
  for (int i = R; i > mid; --i) {
    p = i - mx[i] + mn[i];
    if (p <= mid && p >= L && mx[p] < mx[i] && mn[p] > mn[i]) ++ans;
  }
  p = q = mid + 1;
  for (int i = mid; i >= L; --i) {
    while (q <= R && mn[q] > mn[i]) ++s[mx[q] - q + n], ++q;
    while (p < q && mx[p] < mx[i]) --s[mx[p] - p + n], ++p;
    ans += s[mn[i] - i + n];
  }
  while (p < q) --s[mx[p] - p + n], ++p;
  p = q = mid;
  for (int i = mid + 1; i <= R; ++i) {
    while (p >= L && mn[p] > mn[i]) ++s[mx[p] + p], --p;
    while (p < q && mx[q] < mx[i]) --s[mx[q] + q], --q;
    ans += s[mn[i] + i];
  }
  while (p < q) --s[mx[q] + q], --q;
  return;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[read()] = read();
  CDQ(1, n);
  cout << ans;
  return 0;
}
