#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
long long as;
int n, a[300005];
int mn[300005], mx[300005];
int fir[300005], to[300005 * 18], nxt[300005 * 18], ct, w[300005 * 18];
int ans[300005];
int cnt[300005 << 1];
void add(int x, int y, int z) {
  nxt[++ct] = fir[x];
  to[ct] = y;
  fir[x] = ct;
  w[ct] = z;
}
void solve(int l, int r) {
  if (l == r) {
    as++;
    return;
  }
  int mx_ = 0, mn_ = n + 1;
  for (int i = ((l + r) >> 1); i >= l; i--)
    mx_ = mx[i] = max(mx_, a[i]), mn_ = mn[i] = min(mn_, a[i]),
    fir[i] = ans[i] = 0;
  mx_ = 0, mn_ = n + 1;
  for (int i = ((l + r) >> 1) + 1; i <= r; i++)
    mx_ = mx[i] = max(mx_, a[i]), mn_ = mn[i] = min(mn_, a[i]),
    fir[i] = ans[i] = 0;
  for (int i = ((l + r) >> 1), j = ((l + r) >> 1), k = ((l + r) >> 1); i >= l;
       i--) {
    while (mx[j + 1] < mx[i] && j < r) j++;
    while (mn[k + 1] > mn[i] && k < r) k++;
    if (k < j && mx[i] - ((l + r) >> 1) - 1 + i > 0) {
      if (k > ((l + r) >> 1)) add(k, i, -(mx[i] - ((l + r) >> 1) - 1 + i));
      add(j, i, mx[i] - ((l + r) >> 1) - 1 + i);
    }
    int z = min(j, k) - ((l + r) >> 1), c = mx[i] - mn[i] - ((l + r) >> 1) + i;
    ans[i] += (c >= 1 && c <= z);
  }
  for (int i = ((l + r) >> 1) + 1, j = ((l + r) >> 1) + 1,
           k = ((l + r) >> 1) + 1;
       i <= r; i++) {
    while (mx[j - 1] < mx[i] && j > l) j--;
    while (mn[k - 1] > mn[i] && k > l) k--;
    if (k > j && mx[i] - i + ((l + r) >> 1) > 0) {
      if (k <= ((l + r) >> 1)) add(k, i, -(mx[i] - i + ((l + r) >> 1)));
      add(j, i, mx[i] - i + ((l + r) >> 1));
    }
    int z = ((l + r) >> 1) - max(j, k) + 1,
        c = mx[i] - mn[i] - i + ((l + r) >> 1) + 1;
    ans[i] += (c >= 1 && c <= z);
  }
  for (int i = ((l + r) >> 1) + 1; i <= r; i++) {
    cnt[mn[i] + i - ((l + r) >> 1) - 1]++;
    for (int j = fir[i]; j; j = nxt[j]) {
      int on = w[j] / abs(w[j]), y = to[j];
      ans[y] += on * cnt[abs(w[j])];
    }
  }
  for (int i = ((l + r) >> 1) + 1; i <= r; i++)
    cnt[mn[i] + i - ((l + r) >> 1) - 1]--;
  for (int i = ((l + r) >> 1); i >= l; i--) {
    cnt[mn[i] + ((l + r) >> 1) - i]++;
    for (int j = fir[i]; j; j = nxt[j]) {
      int on = w[j] / abs(w[j]), y = to[j];
      ans[y] += on * cnt[abs(w[j])];
    }
  }
  for (int i = ((l + r) >> 1); i >= l; i--) cnt[mn[i] + ((l + r) >> 1) - i]--;
  for (int i = l; i <= r; i++) as += ans[i];
  solve(l, ((l + r) >> 1));
  solve(((l + r) >> 1) + 1, r);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    a[x] = read();
  }
  solve(1, n);
  printf("%lld\n", as);
}
