#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, a[maxn];
long long ans;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
struct node {
  int val, cnt, lazy;
} tr[maxn << 2];
inline void upt(int h) {
  if (tr[h << 1].val < tr[h << 1 | 1].val)
    tr[h].cnt = tr[h << 1].cnt;
  else if (tr[h << 1].val > tr[h << 1 | 1].val)
    tr[h].cnt = tr[h << 1 | 1].cnt;
  else
    tr[h].cnt = tr[h << 1].cnt + tr[h << 1 | 1].cnt;
  tr[h].val = min(tr[h << 1].val, tr[h << 1 | 1].val);
}
inline void build(int h, int l, int r) {
  if (l == r) {
    tr[h].val = l;
    tr[h].cnt = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(h << 1, l, mid);
  build(h << 1 | 1, mid + 1, r);
  upt(h);
  return;
}
inline void pushup(int h, int l, int r, int t) {
  tr[h].val += t;
  tr[h].lazy += t;
}
inline void pushdown(int h, int l, int r) {
  if (!tr[h].lazy) return;
  int mid = (l + r) >> 1;
  pushup(h << 1, l, mid, tr[h].lazy);
  pushup(h << 1 | 1, mid + 1, r, tr[h].lazy);
  tr[h].lazy = 0;
}
inline void update(int h, int l, int r, int x, int y, int t) {
  if (l > y || r < x) return;
  if (l >= x && r <= y) {
    pushup(h, l, r, t);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(h, l, r);
  update(h << 1, l, mid, x, y, t);
  update(h << 1 | 1, mid + 1, r, x, y, t);
  upt(h);
  return;
}
inline int query(int h, int l, int r, int x, int y) {
  if (l > y || r < x) return 0;
  if (l >= x && r <= y) {
    if (tr[h].val == 0) return tr[h].cnt;
    return 0;
  }
  pushdown(h, l, r);
  int mid = (l + r) >> 1;
  return query(h << 1, l, mid, x, y) + query(h << 1 | 1, mid + 1, r, x, y);
}
int st1[maxn], st2[maxn], top1, top2;
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);
  for (int i = 1; i <= n; i++) {
    update(1, 1, n, 1, n, -1);
    while (top1 && a[st1[top1]] < a[i]) {
      update(1, 1, n, st1[top1 - 1] + 1, st1[top1], a[i] - a[st1[top1]]);
      top1--;
    }
    while (top2 && a[st2[top2]] > a[i]) {
      update(1, 1, n, st2[top2 - 1] + 1, st2[top2], a[st2[top2]] - a[i]);
      top2--;
    }
    st1[++top1] = st2[++top2] = i;
    ans += query(1, 1, n, 1, i);
  }
  printf("%lld\n", ans);
  return 0;
}
