#include <bits/stdc++.h>
using namespace std;
int a[300005], n, t[600005];
long long ans;
struct node {
  int maxn, minn, num;
} k[300005];
void solve(int l, int r) {
  if (l == r) {
    ans++;
    return;
  }
  int mid = (l + r) >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  k[mid].maxn = a[mid];
  k[mid].minn = a[mid];
  k[mid + 1].maxn = a[mid + 1];
  k[mid + 1].minn = a[mid + 1];
  for (int i = mid - 1; i >= l; i--) {
    k[i].maxn = max(k[i + 1].maxn, a[i]);
    k[i].minn = min(k[i + 1].minn, a[i]);
  }
  for (int i = mid + 2; i <= r; i++) {
    k[i].maxn = max(k[i - 1].maxn, a[i]);
    k[i].minn = min(k[i - 1].minn, a[i]);
  }
  for (int i = mid; i >= l; i--) {
    int tp = i + k[i].maxn - k[i].minn;
    if (tp <= mid || tp > r) continue;
    if (k[tp].maxn < k[i].maxn && k[tp].minn > k[i].minn) ans++;
  }
  for (int i = mid + 1; i <= r; i++) {
    int tp = i - k[i].maxn + k[i].minn;
    if (tp > mid || tp < l) continue;
    if (k[tp].maxn < k[i].maxn && k[tp].minn > k[i].minn) ans++;
  }
  int i1 = mid + 1, i2 = mid + 1;
  for (int i = mid; i >= l; i--) {
    while (i1 <= r && k[i1].maxn < k[i].maxn) t[k[i1].minn + i1]++, i1++;
    while (i2 < i1 && k[i2].minn > k[i].minn) t[k[i2].minn + i2]--, i2++;
    ans += t[i + k[i].maxn];
  }
  for (int i = i2; i < i1; i++) t[k[i].minn + i]--;
  i1 = mid, i2 = mid;
  for (int i = mid + 1; i <= r; i++) {
    while (i1 >= l && k[i1].maxn < k[i].maxn)
      t[k[i1].minn - i1 + 300000]++, i1--;
    while (i2 > i1 && k[i2].minn > k[i].minn)
      t[k[i2].minn - i2 + 300000]--, i2--;
    ans += t[k[i].maxn - i + 300000];
  }
  for (int i = i1 + 1; i <= i2; i++) t[k[i].minn - i + 300000]--;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u] = v;
  }
  solve(1, n);
  cout << ans;
}
