#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10000020;
int bufpos;
char buf[MAXSIZE];
void init() {
  buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
  bufpos = 0;
}
int readint() {
  int val = 0;
  for (; !isdigit(buf[bufpos]); bufpos++)
    ;
  for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] - '0';
  return val;
}
const int INF = 0x3f3f3f3f;
struct atom {
  int mmin, minc;
  atom() { mmin = INF, minc = 0; }
  atom(int x) { mmin = x, minc = 1; }
  atom& operator+=(const atom& rhs) {
    if (mmin == rhs.mmin)
      minc += rhs.minc;
    else if (mmin > rhs.mmin)
      *this = rhs;
    return *this;
  }
  atom operator+(const atom& rhs) const {
    atom w = *this;
    w += rhs;
    return w;
  }
  atom operator+=(const int& v) {
    mmin += v;
    return *this;
  }
  atom operator+(const int& v) const {
    atom w = *this;
    w += v;
    return w;
  }
};
const int maxn = 300001;
struct segtree {
  int n;
  int a[maxn];
  int addv[maxn * 4];
  atom t[maxn * 4];
  void build(int o, int l, int r) {
    if (l == r) {
      t[o].mmin = a[l];
      t[o].minc = 1;
      return;
    }
    int mid = (l + r) / 2;
    build(o * 2, l, mid);
    build(o * 2 + 1, mid + 1, r);
    t[o] = t[o * 2] + t[o * 2 + 1];
  }
  void build() { build(1, 1, n); }
  int ul, ur, uv;
  void update(int o, int l, int r) {
    if (l >= ul && r <= ur) {
      t[o] += uv;
      addv[o] += uv;
      return;
    }
    int mid = (l + r) / 2;
    if (ul <= mid) update(o * 2, l, mid);
    if (ur > mid) update(o * 2 + 1, mid + 1, r);
    t[o] = t[o * 2] + t[o * 2 + 1] + addv[o];
  }
  void modify(int l, int r, int v) {
    ul = l, ur = r, uv = v;
    update(1, 1, n);
  }
  int ql, qr;
  atom query(int o, int l, int r, int add) {
    if (l >= ql && r <= qr) {
      return t[o] + add;
    }
    atom res;
    int mid = (l + r) / 2;
    if (ql <= mid) res += query(o * 2, l, mid, add + addv[o]);
    if (qr > mid) res += query(o * 2 + 1, mid + 1, r, add + addv[o]);
    return res;
  }
  atom query(int l, int r) {
    ql = l, qr = r;
    return query(1, 1, n, 0);
  }
} t;
int a[maxn];
int q1[maxn + 1], q2[maxn + 1];
int main() {
  init();
  int n = readint();
  for (int i = 1; i <= n; i++) {
    int x = readint();
    a[x] = readint();
  }
  t.n = n;
  for (int i = 1; i <= n; i++) t.a[i] = n - i;
  t.build();
  int l1 = n + 1, l2 = n + 1;
  q1[n + 1] = q2[n + 1] = n + 1;
  long long ans = 0;
  for (int i = n; i; i--) {
    while (l1 <= n && a[q1[l1]] <= a[i])
      t.modify(q1[l1], q1[l1 + 1] - 1, a[i] - a[q1[l1]]), l1++;
    q1[--l1] = i;
    while (l2 <= n && a[q2[l2]] >= a[i])
      t.modify(q2[l2], q2[l2 + 1] - 1, a[q2[l2]] - a[i]), l2++;
    q2[--l2] = i;
    atom w = t.query(i, n);
    ans += w.minc;
    t.modify(1, n, -1);
  }
  printf("%lld", ans);
}
