#include <bits/stdc++.h>
using namespace std;
int gi() {
  int res = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
  return res * w;
}
const int T = 3e5;
const int MAX_N = 3e5 + 5;
int N, a[MAX_N];
long long ans = 0;
int mn[MAX_N], mx[MAX_N], buc[MAX_N << 1];
void Div(int l, int r) {
  if (l == r) return (void)(++ans);
  int mid = (l + r) >> 1;
  Div(l, mid), Div(mid + 1, r);
  mx[mid] = mn[mid] = a[mid];
  mx[mid + 1] = mn[mid + 1] = a[mid + 1];
  for (int i = mid + 2; i <= r; i++)
    mn[i] = min(mn[i - 1], a[i]), mx[i] = max(mx[i - 1], a[i]);
  for (int i = mid - 1; i >= l; i--)
    mn[i] = min(mn[i + 1], a[i]), mx[i] = max(mx[i + 1], a[i]);
  int j = mid, k = mid;
  for (int i = mid + 1; i <= r; i++) {
    while (k >= l && mx[k] < mx[i]) ++buc[mn[k] - k + T], --k;
    while (j >= l && mn[j] > mn[i] && mx[j] < mx[i]) buc[mn[j] - j + T]--, --j;
    ans += buc[mx[i] - i + T];
    if (j < mid) ans += (i + mn[i] - mx[i] > j) && (i + mn[i] - mx[i] <= mid);
  }
  for (int i = l; i <= mid; i++) buc[mn[i] - i + T] = 0;
  j = k = mid + 1;
  for (int i = mid; i >= l; i--) {
    while (k <= r && mx[k] < mx[i]) ++buc[mn[k] + k], ++k;
    while (j <= r && mn[j] > mn[i] && mx[j] < mx[i]) buc[mn[j] + j]--, ++j;
    ans += buc[mx[i] + i];
    if (j > mid + 1)
      ans += (i + mx[i] - mn[i] > mid) && (i + mx[i] - mn[i] < j);
  }
  for (int i = mid + 1; i <= r; i++) buc[mn[i] + i] = 0;
}
int main() {
  N = gi();
  for (int i = 1; i <= N; i++) a[gi()] = gi();
  Div(1, N);
  printf("%lld\n", ans);
  return 0;
}
