#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void read(int &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int N = 3e5 + 10;
int n, a[N], ta, tb, sa[N], sb[N];
struct seg_tree {
  int c[N << 2], tag[N << 2];
  long long num[N << 2];
  void build(int p, int l, int r) {
    num[p] = r - l + 1;
    if (l == r) return;
    int mid(l + r >> 1);
    build((p << 1), l, mid), build((p << 1 | 1), mid + 1, r);
  }
  void push_down(int p) {
    tag[(p << 1)] += tag[p], tag[(p << 1 | 1)] += tag[p];
    c[(p << 1)] += tag[p], c[(p << 1 | 1)] += tag[p], tag[p] = 0;
  }
  void push_up(int p) {
    if (c[(p << 1)] == c[(p << 1 | 1)])
      c[p] = c[(p << 1)], num[p] = num[(p << 1)] + num[(p << 1 | 1)];
    else if (c[(p << 1)] < c[(p << 1 | 1)])
      c[p] = c[(p << 1)], num[p] = num[(p << 1)];
    else
      c[p] = c[(p << 1 | 1)], num[p] = num[(p << 1 | 1)];
  }
  void modify(int p, int l, int r, int ql, int qr, int v) {
    if (ql <= l && r <= qr) {
      c[p] += v, tag[p] += v;
      return;
    }
    int mid(l + r >> 1);
    push_down(p);
    if (ql <= mid) modify((p << 1), l, mid, ql, qr, v);
    if (qr > mid) modify((p << 1 | 1), mid + 1, r, ql, qr, v);
    push_up(p);
  }
  pair<int, long long> query(int p, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return make_pair(c[p], num[p]);
    int mid(l + r >> 1), mn = 1e9;
    long long cnt = 0;
    push_down(p);
    if (ql <= mid) {
      pair<int, long long> tmp = query((p << 1), l, mid, ql, qr);
      if (tmp.first < mn)
        mn = tmp.first, cnt = tmp.second;
      else if (tmp.first == mn)
        cnt += tmp.second;
    }
    if (qr > mid) {
      pair<int, long long> tmp = query((p << 1 | 1), mid + 1, r, ql, qr);
      if (tmp.first < mn)
        mn = tmp.first, cnt = tmp.second;
      else if (tmp.first == mn)
        cnt += tmp.second;
    }
    return make_pair(mn, cnt);
  }
} T;
signed main() {
  read(n);
  T.build(1, 1, n);
  long long res = 0;
  for (int i = 1, x, y; i <= n; ++i) read(x), read(y), a[x] = y;
  for (int i = 1; i <= n; ++i) {
    while (ta && a[sa[ta]] < a[i])
      T.modify(1, 1, n, sa[ta - 1] + 1, sa[ta], -a[sa[ta]]), --ta;
    while (tb && a[sb[tb]] > a[i])
      T.modify(1, 1, n, sb[tb - 1] + 1, sb[tb], a[sb[tb]]), --tb;
    T.modify(1, 1, n, sa[ta] + 1, i, a[i]), sa[++ta] = i;
    T.modify(1, 1, n, sb[tb] + 1, i, -a[i]), sb[++tb] = i;
    T.modify(1, 1, n, 1, i, -1), res += T.query(1, 1, n, 1, i).second;
  }
  return printf("%lld\n", res), 0;
}
