#include <bits/stdc++.h>
using namespace std;
const int MaxN = 300010;
int P[MaxN], N;
long long ans = 0;
int Cnt[MaxN * 2];
long long Work(int l, int r) {
  int mid = (l + r) >> 1;
  long long ret = 0;
  static int lmin[MaxN], rmin[MaxN], lmax[MaxN], rmax[MaxN];
  lmin[mid + 1] = N;
  lmax[mid + 1] = 0;
  rmin[mid] = N;
  rmax[mid] = 0;
  for (int i = mid, __end = l; i >= __end; --i) {
    lmin[i] = min(lmin[i + 1], P[i]);
    lmax[i] = max(lmax[i + 1], P[i]);
  }
  for (int i = mid + 1, __end = r; i <= __end; ++i) {
    rmin[i] = min(rmin[i - 1], P[i]);
    rmax[i] = max(rmax[i - 1], P[i]);
  }
  for (int i = l, __end = mid; i <= __end; ++i) {
    int pos = i + lmax[i] - lmin[i];
    if ((pos <= mid) | (pos > r)) continue;
    if ((rmax[pos] <= lmax[i]) && (rmin[pos] >= lmin[i])) ret++;
  }
  for (int i = mid + 1, __end = r; i <= __end; ++i) {
    int pos = i - rmax[i] + rmin[i];
    if ((pos > mid) || (pos < l)) continue;
    if ((lmax[pos] <= rmax[i]) && (lmin[pos] >= rmin[i])) ret++;
  }
  for (int i = l, __end = mid; i <= __end; ++i) Cnt[lmin[i] - i + MaxN] = 0;
  int lnode = mid + 1, rnode = mid;
  for (int i = mid, __end = l; i >= __end; --i) {
    while ((lnode <= r) && (rmax[lnode] < lmax[i])) {
      Cnt[rmax[lnode] - lnode + MaxN]--;
      lnode++;
    }
    while ((rnode + 1 <= r) && (rmin[rnode + 1] > lmin[i])) {
      rnode++;
      Cnt[rmax[rnode] - rnode + MaxN]++;
    }
    if (lnode <= rnode) ret += Cnt[lmin[i] - i + MaxN];
  }
  for (int i = l, __end = mid; i <= __end; ++i) Cnt[i + lmax[i]] = 0;
  lnode = mid + 1, rnode = mid;
  for (int i = mid, __end = l; i >= __end; --i) {
    while ((lnode <= r) && (rmin[lnode] > lmin[i])) {
      Cnt[rmin[lnode] + lnode]--;
      lnode++;
    }
    while ((rnode + 1 <= r) && (rmax[rnode + 1] < lmax[i])) {
      rnode++;
      Cnt[rmin[rnode] + rnode]++;
    }
    if (lnode <= rnode) ret += Cnt[i + lmax[i]];
  }
  return ret;
}
void Solve(int l, int r) {
  if (l == r) {
    ans++;
    return;
  }
  int mid = (l + r) >> 1;
  Solve(l, mid);
  Solve(mid + 1, r);
  ans += Work(l, r);
}
int main() {
  scanf("%d", &N);
  for (int i = 1, __end = N; i <= __end; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    P[x] = y;
  }
  Solve(1, N);
  cout << ans << endl;
  return 0;
}
