#include <bits/stdc++.h>
inline long long read() {
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  long long k = 0, kk = 1;
  if (c == '-') c = getchar(), kk = -1;
  while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
  return kk * k;
}
using namespace std;
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x / 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
long long n, ma[2000010], mi[2000010], ans, z[2000010], d, t[2000010],
    a[2000010], x;
void solve(long long l, long long r) {
  if (l == r) {
    ans++;
    return;
  }
  long long m = (l + r) / 2;
  mi[m] = ma[m] = a[m];
  mi[m + 1] = ma[m + 1] = a[m + 1];
  for (long long i = m - 1; i >= l; i--)
    ma[i] = max(ma[i + 1], a[i]), mi[i] = min(mi[i + 1], a[i]);
  for (long long i = m + 2; i <= r; i++)
    ma[i] = max(ma[i - 1], a[i]), mi[i] = min(mi[i - 1], a[i]);
  for (long long i = l; i <= m; i++) {
    long long j = ma[i] - mi[i] + i;
    if (j > m && j <= r && ma[j] < ma[i] && mi[j] > mi[i]) ans++;
  }
  for (long long j = m + 1; j <= r; j++) {
    long long i = -(ma[j] - mi[j] - j);
    if (i >= l && i <= m && ma[j] > ma[i] && mi[j] < mi[i]) ans++;
  }
  long long L = m + 1, R = m + 1;
  for (long long i = m; i >= l; i--) {
    for (; ma[i] > ma[R] && R <= r; R++) t[mi[R] + R]++;
    for (; mi[L] > mi[i] && L < R; L++) t[mi[L] + L]--;
    ans += t[ma[i] + i];
  }
  for (; L < R; L++) t[mi[L] + L]--;
  L = m;
  R = m;
  for (long long j = m + 1; j <= r; j++) {
    for (; ma[L] < ma[j] && L >= l; L--) t[mi[L] - L + n]++;
    for (; mi[j] < mi[R] && R > L; R--) t[mi[R] - R + n]--;
    ans += t[ma[j] - j + n];
  }
  for (; L < R; R--) t[mi[R] - R + n]--;
  solve(l, m);
  solve(m + 1, r);
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) x = read(), a[x] = read();
  solve(1, n);
  cout << ans << endl;
}
