#include <bits/stdc++.h>
using namespace std;
int read() {
  int X = 0;
  char ch = 0;
  while (ch < 48 || ch > 57) ch = getchar();
  while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar();
  return X;
}
struct Node {
  int x, c, tg;
  inline void add(int _t) {
    x += _t;
    tg += _t;
  }
} a[300500 << 2];
inline void up(int u) {
  int l = u << 1, r = u << 1 | 1;
  a[u].x = min(a[l].x, a[r].x);
  a[u].c = (a[l].x == a[r].x)  ? a[l].c + a[r].c
           : (a[l].x < a[r].x) ? a[l].c
                               : a[r].c;
}
inline void ladd(int u) {
  if (a[u].tg) {
    a[u << 1].add(a[u].tg);
    a[u << 1 | 1].add(a[u].tg);
    a[u].tg = 0;
  }
}
int n, wfl, wfr, wfc;
void add(int l = 1, int r = n, int u = 1) {
  if (wfl <= l && r <= wfr) {
    a[u].add(wfc);
    return;
  }
  int mid = (l + r) >> 1;
  ladd(u);
  if (wfl <= mid) add(l, mid, u << 1);
  if (mid < wfr) add(mid + 1, r, u << 1 | 1);
  up(u);
}
void build(int l = 1, int r = n, int u = 1) {
  if (l == r) {
    a[u].x = l;
    a[u].c = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, u << 1);
  build(mid + 1, r, u << 1 | 1);
  up(u);
}
int x[300500], stk0[300500], t0, stk1[300500], t1;
int main() {
  n = read();
  for (int i = 1, t; i <= n; i++) {
    t = read();
    x[t] = read();
  }
  build();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    while (t0 && x[stk0[t0]] > x[i]) {
      wfl = stk0[t0 - 1] + 1;
      wfr = stk0[t0];
      wfc = x[stk0[t0--]] - x[i];
      add();
    }
    while (t1 && x[stk1[t1]] < x[i]) {
      wfl = stk1[t1 - 1] + 1;
      wfr = stk1[t1];
      wfc = x[i] - x[stk1[t1--]];
      add();
    }
    stk0[++t0] = i;
    stk1[++t1] = i;
    ans += a[1].c;
  }
  printf("%lld", ans);
  return 0;
}
