#include <bits/stdc++.h>
using namespace std;
int n, m;
int read() {
  char ch = getchar();
  int x = 0, f = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch - '0');
  return f * x;
}
long long ans = 0;
int a[300100];
int num[1001000];
int minn[300100], maxx[300100];
void work(int l, int r) {
  if (l == r) {
    ans++;
    return;
  }
  int mid = l + r >> 1;
  work(l, mid);
  work(mid + 1, r);
  maxx[mid] = minn[mid] = a[mid];
  maxx[mid + 1] = minn[mid + 1] = a[mid + 1];
  for (int i = mid - 1; i >= l; i--) {
    maxx[i] = max(maxx[i + 1], a[i]);
    minn[i] = min(minn[i + 1], a[i]);
  }
  for (int i = mid + 2; i <= r; i++) {
    maxx[i] = max(maxx[i - 1], a[i]);
    minn[i] = min(minn[i - 1], a[i]);
  }
  for (int i = mid; i >= l; i--) {
    int j = maxx[i] - minn[i] + i;
    if (mid < j && j <= r && maxx[j] < maxx[i] && minn[i] < minn[j]) ans++;
  }
  for (int i = mid + 1; i <= r; i++) {
    int j = minn[i] - maxx[i] + i;
    if (l <= j && j <= mid && maxx[j] < maxx[i] && minn[i] < minn[j]) ans++;
  }
  int j = mid + 1, k = mid + 1;
  for (int i = mid; i >= l; i--) {
    for (; j <= r && minn[j] > minn[i]; j++) num[maxx[j] - j + n]++;
    for (; k < j && maxx[k] < maxx[i]; k++) num[maxx[k] - k + n]--;
    ans += num[minn[i] - i + n];
  }
  for (; k < j; k++) num[maxx[k] - k + n]--;
  j = mid, k = mid;
  for (int i = mid + 1; i <= r; i++) {
    for (; j >= l && minn[j] > minn[i]; j--) num[maxx[j] + j]++;
    for (; k > j && maxx[k] < maxx[i]; k--) num[maxx[k] + k]--;
    ans += num[minn[i] + i];
  }
  for (; k > j; k--) num[maxx[k] + k]--;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    a[x] = y;
  }
  work(1, n);
  printf("%lld\n", ans);
  return 0;
}
