#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  return x * f;
}
const long long N = 300005;
long long a[N];
long long mx[N], mn[N];
long long tx, tn;
long long n;
long long tr[N << 2], L[N << 2], R[N << 2], cnt[N << 2], tag[N << 2];
void pushup(long long k) {
  cnt[k] = 0;
  tr[k] = min(tr[k << 1], tr[k << 1 | 1]);
  if (tr[k] == tr[k << 1]) cnt[k] += cnt[k << 1];
  if (tr[k] == tr[k << 1 | 1]) cnt[k] += cnt[k << 1 | 1];
}
void biu(long long k, long long l, long long r) {
  L[k] = l;
  R[k] = r;
  if (l == r) {
    tr[k] = l;
    cnt[k] = 1;
    return;
  }
  long long mid = (l + r) >> 1;
  biu(k << 1, l, mid);
  biu(k << 1 | 1, mid + 1, r);
  pushup(k);
}
void pushd(long long k) {
  if (tag[k]) {
    tr[k << 1] += tag[k];
    tag[k << 1] += tag[k];
    tr[k << 1 | 1] += tag[k];
    tag[k << 1 | 1] += tag[k];
    tag[k] = 0;
  }
}
void ad(long long k, long long l, long long r, long long x) {
  if (L[k] >= l && R[k] <= r) {
    tr[k] += x;
    tag[k] += x;
    return;
  }
  pushd(k);
  long long mid = (L[k] + R[k]) >> 1;
  if (l <= mid) ad(k << 1, l, r, x);
  if (r > mid) ad(k << 1 | 1, l, r, x);
  pushup(k);
}
signed main() {
  n = read();
  long long ans = 0;
  long long x;
  for (long long i = 1; i <= n; ++i) a[x = read()] = read();
  biu(1, 1, n);
  for (long long i = 1; i <= n; ++i) {
    while (tx && a[mx[tx]] < a[i]) {
      ad(1, mx[tx - 1] + 1, mx[tx], -a[mx[tx]]);
      --tx;
    }
    while (tn && a[mn[tn]] > a[i]) {
      ad(1, mn[tn - 1] + 1, mn[tn], a[mn[tn]]);
      --tn;
    }
    ad(1, mx[tx] + 1, i, a[i]);
    ad(1, mn[tn] + 1, i, -a[i]);
    if (tr[1] == i) ans += cnt[1];
    mx[++tx] = i;
    mn[++tn] = i;
  }
  printf("%lld", ans);
}
