#include <bits/stdc++.h>
using namespace std;
int n, a[300009];
stack<int> mi, ma;
struct data {
  int x, y;
  data(int o = 1000000000, int z = 0) { x = o, y = z; }
  data operator+(const data b) const {
    data c;
    c.x = min(x, b.x);
    if (x == c.x) c.y += y;
    if (b.x == c.x) c.y += b.y;
    return c;
  }
} s[300009 << 2];
int lazy[300009 << 2];
void mark(int now, int v) {
  lazy[now] += v;
  s[now].x += v;
}
void pushdown(int now) {
  if (lazy[now]) {
    mark(now << 1, lazy[now]);
    mark(now << 1 | 1, lazy[now]);
    lazy[now] = 0;
  }
}
void modify(int l, int r, int now, int p, int v) {
  if (l == r) {
    s[now].x = v;
    s[now].y = 1;
    return;
  }
  pushdown(now);
  int mid = (l + r) >> 1;
  if (p <= mid)
    modify(l, mid, now << 1, p, v);
  else
    modify(mid + 1, r, now << 1 | 1, p, v);
  s[now] = s[now << 1] + s[now << 1 | 1];
}
void update(int l, int r, int now, int L, int R, int v) {
  if (l >= L && r <= R) {
    mark(now, v);
    return;
  }
  pushdown(now);
  int mid = (l + r) >> 1;
  if (L <= mid) update(l, mid, now << 1, L, R, v);
  if (R > mid) update(mid + 1, r, now << 1 | 1, L, R, v);
  s[now] = s[now << 1] + s[now << 1 | 1];
}
data query(int l, int r, int now, int L, int R) {
  if (l >= L && r <= R) {
    return s[now];
  }
  pushdown(now);
  int mid = (l + r) >> 1;
  if (L <= mid && R > mid) {
    return query(l, mid, now << 1, L, R) +
           query(mid + 1, r, now << 1 | 1, L, R);
  } else if (L <= mid)
    return query(l, mid, now << 1, L, R);
  else
    return query(mid + 1, r, now << 1 | 1, L, R);
}
int pmi[300009], pma[300009];
int main() {
  scanf("%d", &n);
  int x, y, z;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    a[y] = x;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    modify(1, n, 1, i, i);
    z = i - 1;
    while (!mi.empty() && a[i] < a[mi.top()]) {
      update(1, n, 1, pmi[mi.top()], z, a[mi.top()] - a[i]);
      z = mi.top() - 1;
      mi.pop();
    }
    z = i - 1;
    while (!ma.empty() && a[i] > a[ma.top()]) {
      update(1, n, 1, pma[ma.top()], z, a[i] - a[ma.top()]);
      z = ma.top() - 1;
      ma.pop();
    }
    pmi[i] = mi.empty() ? 1 : mi.top() + 1;
    pma[i] = ma.empty() ? 1 : ma.top() + 1;
    mi.push(i);
    ma.push(i);
    ans += s[1].y;
  }
  printf("%lld\n", ans);
  return 0;
}
