#include <bits/stdc++.h>
using namespace std;
int n, w[301000];
long long Res;
struct IdxTree {
  int M, C;
} IT[1000010];
int Mx[301000], Mn[301000];
void UDT(int nd) {
  IT[nd] = IT[nd * 2];
  if (IT[nd].M > IT[nd * 2 + 1].M)
    IT[nd] = IT[nd * 2 + 1];
  else if (IT[nd].M == IT[nd * 2 + 1].M)
    IT[nd].C += IT[nd * 2 + 1].C;
}
void Add(int nd, int M, int C) {
  nd += 500005;
  IT[nd].M = M, IT[nd].C = C;
  while (nd != 1) {
    nd /= 2;
    UDT(nd);
  }
}
int Gap(int b, int e) {
  int r;
  r = 1000000000;
  b += 500005, e += 500005;
  while (b <= e) {
    r = min(r, IT[b].M);
    r = min(r, IT[e].M);
    b = (b + 1) / 2;
    e = (e - 1) / 2;
  }
  return r;
}
int Sum(int b, int e, int t) {
  int r;
  r = 0;
  b += 500005, e += 500005;
  while (b <= e) {
    if (b % 2 == 1 && IT[b].M == t) r += IT[b].C;
    if (e % 2 == 0 && IT[e].M == t) r += IT[e].C;
    b = (b + 1) / 2;
    e = (e - 1) / 2;
  }
  return r;
}
void Do(int b, int e) {
  int pv, m, i, MMx = -1, MMn = n + 1, bb, t, ee;
  if (b == e) {
    Res++;
    return;
  }
  m = (b + e) / 2;
  Do(b, m);
  Do(m + 1, e);
  for (i = m; i >= b; i--) {
    if (MMx < w[i]) MMx = w[i];
    if (MMn > w[i]) MMn = w[i];
    Mx[i] = MMx, Mn[i] = MMn;
  }
  MMx = -1, MMn = n + 1;
  for (i = m + 1; i <= e; i++) {
    if (MMx < w[i]) MMx = w[i];
    if (MMn > w[i]) MMn = w[i];
    Mx[i] = MMx, Mn[i] = MMn;
  }
  for (i = m + 1; i <= e; i++) Add(i, Mx[i] - i, 1);
  pv = m;
  for (i = m; i >= b; i--) {
    while (pv + 1 <= e && Mn[pv + 1] > Mn[i]) pv += 1;
    bb = i + Mx[i] - Mn[i];
    if (bb == m) bb = m + 1;
    if (bb > pv) continue;
    t = Gap(bb, bb);
    if (t <= Mn[i] - i) Res++;
    bb += 1;
    if (bb > pv) continue;
    t = Gap(bb, pv);
    if (t != Mn[i] - i) continue;
    Res += Sum(bb, pv, t);
  }
  for (i = b; i <= m; i++) Add(i, Mx[i] + i, 1);
  pv = m + 1;
  for (i = m + 1; i <= e; i++) {
    while (pv - 1 >= b && Mn[pv - 1] > Mn[i]) pv -= 1;
    ee = i - (Mx[i] - Mn[i]);
    if (ee == m + 1) ee = m;
    if (ee < pv) continue;
    t = Gap(ee, ee);
    if (t <= Mn[i] + i) Res += 1;
    ee -= 1;
    if (ee < pv) continue;
    t = Gap(pv, ee);
    if (t != Mn[i] + i) continue;
    Res += Sum(pv, ee, t);
  }
}
int main(void) {
  int i, a, b;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &a, &b);
    w[a] = b;
  }
  Do(1, n);
  printf("%I64d\n", Res);
}
