#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') f = ch == '-' ? -1 : f, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int maxn = 1e6 + 5;
int n;
int a[maxn];
int Max[maxn], Min[maxn], cnt[maxn];
long long ans;
void work(int l, int r, int mid) {
  Max[mid] = Min[mid] = a[mid];
  for (int i = mid - 1; i >= l; i--) {
    Max[i] = max(a[i], Max[i + 1]);
    Min[i] = min(a[i], Min[i + 1]);
  }
  Max[mid + 1] = Min[mid + 1] = a[mid + 1];
  for (int i = mid + 2; i <= r; i++) {
    Max[i] = max(a[i], Max[i - 1]);
    Min[i] = min(a[i], Min[i - 1]);
  }
  int L = mid + 1, R = mid, j = mid;
  for (int i = mid; i >= l; i--) {
    while (j < r && Max[i] > Max[j + 1] && Min[i] < Min[j + 1]) j++;
    if (Max[i] - Min[i] == j - i && j > mid) ans++;
    while (R < r && Max[i] > Max[R + 1]) R++, cnt[R + Min[R]]++;
    while (L <= r && Min[i] < Min[L]) cnt[L + Min[L]]--, L++;
    ans += max(cnt[Max[i] + i], 0);
  }
  while (L <= r) cnt[L + Min[L]]--, L++;
  while (R < r) R++, cnt[R + Min[R]]++;
}
void solve(int l, int r) {
  if (l == r) {
    ans++;
    return;
  }
  int mid = (l + r) >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  work(l, r, mid);
  reverse(a + l, a + r + 1);
  if ((r - l + 1) % 2 == 1) mid--;
  work(l, r, mid);
  reverse(a + l, a + r + 1);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    a[x] = y;
  }
  solve(1, n);
  printf("%lld\n", ans);
  return 0;
}
