#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N];
int lmx[N], lmn[N], rmx[N], rmn[N];
int cnt[N << 1];
long long ovo(int l, int r) {
  if (l == r) return 1;
  int mid = l + r >> 1;
  long long ret = ovo(l, mid) + ovo(mid + 1, r);
  lmx[mid] = lmn[mid] = a[mid];
  for (int i = mid - 1; i >= l; --i) {
    lmx[i] = max(lmx[i + 1], a[i]);
    lmn[i] = min(lmn[i + 1], a[i]);
  }
  rmx[mid + 1] = rmn[mid + 1] = a[mid + 1];
  for (int i = mid + 2; i <= r; ++i) {
    rmx[i] = max(rmx[i - 1], a[i]);
    rmn[i] = min(rmn[i - 1], a[i]);
  }
  for (int i = l, j; i <= mid; ++i) {
    j = i + lmx[i] - lmn[i];
    if (j > mid && j <= r)
      if (rmx[j] < lmx[i] && rmn[j] > lmn[i]) ++ret;
  }
  for (int i = mid + 1, j; i <= r; ++i) {
    j = i - rmx[i] + rmn[i];
    if (j <= mid && j >= l)
      if (lmx[j] < rmx[i] && lmn[j] > rmn[i]) ++ret;
  }
  for (int i = mid, u = mid, v = mid + 1; i >= l; --i) {
    for (; u < r && rmn[u + 1] > lmn[i]; ++u) ++cnt[rmx[u + 1] - (u + 1) + N];
    for (; v <= min(u, r) && rmx[v] < lmx[i]; ++v) --cnt[rmx[v] - v + N];
    ret += max(0, cnt[lmn[i] - i + N]);
  }
  for (int i = mid + 1; i <= r; ++i) cnt[rmx[i] - i + N] = 0;
  for (int i = mid, u = mid, v = mid + 1; i >= l; --i) {
    for (; u < r && rmx[u + 1] < lmx[i]; ++u) ++cnt[rmn[u + 1] + (u + 1)];
    for (; v <= min(u, r) && rmn[v] > lmn[i]; ++v) --cnt[rmn[v] + v];
    ret += max(0, cnt[lmx[i] + i]);
  }
  for (int i = mid + 1; i <= r; ++i) cnt[rmn[i] + i] = 0;
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1, x, y; i <= n; ++i) scanf("%d%d", &x, &y), a[y] = x;
  cout << ovo(1, n) << endl;
  return 0;
}
