#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int k = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch <= '9' && ch >= '0') k = k * 10 + ch - 48, ch = getchar();
  return k;
}
const int maxn = 3e5 + 5;
int s1[maxn], s2[maxn], top1, top2, a[maxn];
int Min[maxn * 4], tag[maxn * 4], num[maxn * 4];
void push(int now, int c) {
  tag[now] += c;
  Min[now] += c;
}
void pushdown(int now) {
  if (tag[now]) {
    push(now * 2, tag[now]);
    push(now * 2 + 1, tag[now]);
    tag[now] = 0;
  }
}
void pushup(int now) {
  Min[now] = min(Min[now * 2], Min[now * 2 + 1]);
  num[now] = 0;
  if (Min[now * 2] == Min[now]) num[now] += num[now * 2];
  if (Min[now * 2 + 1] == Min[now]) num[now] += num[now * 2 + 1];
}
void build(int now, int l, int r) {
  if (l == r) {
    Min[now] += l;
    num[now] = 1;
    return;
  }
  int mid = l + r >> 1;
  build(now * 2, l, mid);
  build(now * 2 + 1, mid + 1, r);
  pushup(now);
}
void Change(int now, int l, int r, int ql, int qr, int c) {
  if (ql <= l && qr >= r) {
    push(now, c);
    return;
  }
  int mid = l + r >> 1;
  pushdown(now);
  if (ql <= mid) Change(now * 2, l, mid, ql, qr, c);
  if (qr > mid) Change(now * 2 + 1, mid + 1, r, ql, qr, c);
  pushup(now);
}
int n;
int main() {
  n = read();
  int x, y;
  for (int i = 1; i <= n; ++i) {
    x = read();
    y = read();
    a[x] = y;
  }
  build(1, 1, n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    push(1, -1);
    while (top1 >= 1 && a[i] >= a[s1[top1]])
      Change(1, 1, n, s1[top1 - 1] + 1, s1[top1], -a[s1[top1]]), --top1;
    Change(1, 1, n, s1[top1] + 1, i, a[i]);
    s1[++top1] = i;
    while (top2 >= 1 && a[i] <= a[s2[top2]])
      Change(1, 1, n, s2[top2 - 1] + 1, s2[top2], a[s2[top2]]), --top2;
    Change(1, 1, n, s2[top2] + 1, i, -a[i]);
    s2[++top2] = i;
    ans += num[1];
  }
  cout << ans << '\n';
  return 0;
}
