#include <bits/stdc++.h>
using namespace std;
int n;
int a[300005];
int s1[300005], s2[300005];
int h1, h2;
struct Segment_Tree {
  int mn[1200005], cnt[1200005], wp[1200005];
  void pushdown(int now) {
    mn[now << 1] += wp[now];
    mn[now << 1 | 1] += wp[now];
    wp[now << 1] += wp[now];
    wp[now << 1 | 1] += wp[now];
    wp[now] = 0;
  }
  void pushup(int now) {
    mn[now] = min(mn[now << 1], mn[now << 1 | 1]);
    cnt[now] = 0;
    if (mn[now] == mn[now << 1]) {
      cnt[now] += cnt[now << 1];
    }
    if (mn[now] == mn[now << 1 | 1]) {
      cnt[now] += cnt[now << 1 | 1];
    }
  }
  void init(int now = 1, int nl = 1, int nr = n) {
    if (nl == nr) {
      mn[now] = nl;
      cnt[now] = 1;
      return;
    }
    int m = (nl + nr) >> 1;
    init(now << 1, nl, m);
    init(now << 1 | 1, m + 1, nr);
    pushup(now);
  }
  void upd(int l, int r, int x, int now = 1, int nl = 1, int nr = n) {
    if (nl >= l && nr <= r) {
      mn[now] += x;
      wp[now] += x;
      return;
    }
    if (nl > r || nr < l) {
      return;
    }
    pushdown(now);
    int m = (nl + nr) >> 1;
    upd(l, r, x, now << 1, nl, m);
    upd(l, r, x, now << 1 | 1, m + 1, nr);
    pushup(now);
  }
} seg;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x] = y;
  }
  long long ans = 0;
  seg.init();
  for (int i = 1; i <= n; i++) {
    while (h1 && a[s1[h1]] > a[i]) {
      seg.upd(s1[h1 - 1] + 1, s1[h1], a[s1[h1]]);
      h1--;
    }
    seg.upd(s1[h1] + 1, i, -a[i]);
    s1[++h1] = i;
    while (h2 && a[s2[h2]] < a[i]) {
      seg.upd(s2[h2 - 1] + 1, s2[h2], -a[s2[h2]]);
      h2--;
    }
    seg.upd(s2[h2] + 1, i, a[i]);
    s2[++h2] = i;
    ans += seg.cnt[1];
  }
  printf("%lld\n", ans);
  return 0;
}
