#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], minn[1000005][21], maxn[1000005][21], tax[1000005],
    G1[1000005], G2[1000005];
long long ans;
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x < y ? x : y; }
int read() {
  char c = getchar();
  int ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();
  return ans;
}
int query_max(int x, int y) {
  int k = (int)(log2(y - x + 1));
  return max(maxn[x][k], maxn[y - (1 << k) + 1][k]);
}
int query_min(int x, int y) {
  int k = (int)(log2(y - x + 1));
  return min(minn[x][k], minn[y - (1 << k) + 1][k]);
}
void work1(int L, int R, int mid) {
  int now_max = a[mid], now_min = a[mid], p = mid;
  while (p >= L) {
    int r = now_max - now_min + p;
    if (r <= R && r > mid && query_max(p, r) == now_max &&
        query_min(p, r) == now_min)
      ans++;
    p--, now_max = max(now_max, a[p]), now_min = min(now_min, a[p]);
  }
  return;
}
void work2(int L, int R, int mid) {
  int now_max = a[mid + 1], now_min = a[mid + 1], p = mid + 1;
  while (p <= R) {
    int l = p - (now_max - now_min);
    if (l >= L && l <= mid && query_max(l, p) == now_max &&
        query_min(l, p) == now_min)
      ans++;
    p++, now_max = max(now_max, a[p]), now_min = min(now_min, a[p]);
  }
  return;
}
void work3(int L, int R, int mid) {
  G1[mid] = G2[mid] = a[mid], G1[mid + 1] = G2[mid + 1] = a[mid + 1];
  for (register int i = mid - 1; i >= L; i--)
    G1[i] = max(a[i], G1[i + 1]), G2[i] = min(a[i], G2[i + 1]);
  for (register int i = mid + 2; i <= R; i++)
    G1[i] = max(a[i], G1[i - 1]), G2[i] = min(a[i], G2[i - 1]);
  int nowL = mid + 1, nowR = mid;
  for (register int i = mid; i >= L; i--) {
    while (nowR + 1 <= R && G1[nowR + 1] < G1[i])
      ++nowR, tax[G2[nowR] + nowR]++;
    while (nowL <= nowR && G2[nowL] > G2[i]) tax[G2[nowL] + nowL]--, ++nowL;
    ans += tax[G1[i] + i];
  }
  for (register int i = nowL; i <= nowR; i++) tax[G2[i] + i]--;
  nowL = mid + 1, nowR = mid;
  for (register int i = mid + 1; i <= R; i++) {
    while (nowL - 1 >= L && G1[nowL - 1] < G1[i])
      --nowL, tax[G2[nowL] - nowL + n]++;
    while (nowL <= nowR && G2[nowR] > G2[i]) tax[G2[nowR] - nowR + n]--, --nowR;
    ans += tax[G1[i] - i + n];
  }
  for (register int i = nowL; i <= nowR; i++) tax[G2[i] - i + n]--;
  return;
}
void merge(int L, int R) {
  if (L == R) {
    ans++;
    return;
  }
  int mid = (L + R) >> 1;
  merge(L, mid);
  merge(mid + 1, R);
  work1(L, R, mid);
  work2(L, R, mid);
  work3(L, R, mid);
  return;
}
int main() {
  n = read();
  for (register int i = 1, u, v; i <= n; i++)
    u = read(), v = read(), a[u] = v, maxn[u][0] = minn[u][0] = v;
  for (register int j = 1; j <= 20; j++)
    for (register int i = 1; i + (1 << j) - 1 <= n; i++) {
      maxn[i][j] = max(maxn[i][j - 1], maxn[i + (1 << (j - 1))][j - 1]);
      minn[i][j] = min(minn[i][j - 1], minn[i + (1 << (j - 1))][j - 1]);
    }
  merge(1, n);
  printf("%lld", ans);
  return 0;
}
