#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int mx[maxn], mn[maxn], sum[maxn << 1];
int a[maxn], N;
long long ans;
void solve(int L, int R) {
  if (L == R) {
    ans++;
    return;
  }
  int Mid = (L + R) / 2;
  solve(L, Mid);
  solve(Mid + 1, R);
  mx[Mid] = mn[Mid] = a[Mid];
  mx[Mid + 1] = mn[Mid + 1] = a[Mid + 1];
  for (int i = Mid - 1; i >= L; 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]);
  for (int i = Mid + 2; i <= R; i++) mx[i] = max(mx[i - 1], a[i]);
  for (int i = Mid + 2; i <= R; i++) mn[i] = min(mn[i - 1], a[i]);
  for (int i = Mid; i >= L; i--) {
    int j = mx[i] - mn[i] + i;
    if (j <= R && j > Mid && mx[j] < mx[i] && mn[j] > mn[i]) ans++;
  }
  for (int i = Mid + 1; i <= R; i++) {
    int j = i - mx[i] + mn[i];
    if (j <= Mid && j >= L && mx[j] < mx[i] && mn[j] > mn[i]) ans++;
  }
  int j = Mid + 1, k = Mid + 1;
  for (int i = Mid; i >= L; i--) {
    while (j <= R && mn[j] > mn[i]) sum[mx[j] - j + N]++, j++;
    while (k < j && mx[k] < mx[i]) sum[mx[k] - k + N]--, k++;
    ans += (long long)sum[mn[i] - i + N];
  }
  while (k < j) sum[mx[k] - k + N]--, k++;
  j = Mid, k = Mid;
  for (int i = Mid + 1; i <= R; i++) {
    while (j >= L && mn[j] > mn[i]) sum[mx[j] + j]++, j--;
    while (k > j && mx[k] < mx[i]) sum[mx[k] + k]--, k--;
    ans += (long long)sum[mn[i] + i];
  }
  while (k > j) sum[mx[k] + k]--, k--;
}
int main() {
  int x, y, i, j;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%d%d", &x, &y), a[x] = y;
  solve(1, N);
  printf("%lld\n", ans);
  return 0;
}
