#include <bits/stdc++.h>
using namespace std;
long long n, ans, a[300123], maxx[300123], minx[300123], box[800123];
void dopart(long long l, long long r) {
  if (l == r) {
    ans++;
    return;
  }
  long long mid = (l + r) / 2;
  dopart(l, mid);
  dopart(mid + 1, r);
  maxx[mid] = a[mid], minx[mid] = a[mid];
  for (long long i = mid - 1; i >= l; i--) {
    maxx[i] = max(maxx[i + 1], a[i]), minx[i] = min(minx[i + 1], a[i]);
  }
  maxx[mid + 1] = a[mid + 1], minx[mid + 1] = a[mid + 1];
  for (long long i = mid + 2; i <= r; i++) {
    maxx[i] = max(maxx[i - 1], a[i]), minx[i] = min(minx[i - 1], a[i]);
  }
  for (long long i = mid; i >= l; i--) {
    long long now = maxx[i] - minx[i];
    if (i + now <= mid || i + now > r) continue;
    if (maxx[now + i] <= maxx[i] && minx[now + i] >= minx[i]) ans++;
  }
  for (long long i = mid + 1; i <= r; i++) {
    long long now = maxx[i] - minx[i];
    if (i - now >= mid + 1 || i - now < l) continue;
    if (maxx[i - now] <= maxx[i] && minx[i - now] >= minx[i]) ans++;
  }
  long long you1 = mid + 1, you2 = mid + 1;
  for (long long i = mid; i >= l; i--) {
    while (you2 <= r && maxx[you2] < maxx[i]) box[minx[you2] + you2]++, you2++;
    while (you1 < you2 && minx[you1] > minx[i])
      box[minx[you1] + you1]--, you1++;
    ans = ans + box[i + maxx[i]];
  }
  for (long long i = you1; i < you2; i++) box[minx[i] + i]--;
  long long zuo1 = mid, zuo2 = mid;
  for (long long i = mid + 1; i <= r; i++) {
    while (zuo1 >= l && maxx[zuo1] < maxx[i])
      box[minx[zuo1] - zuo1 + n + 1]++, zuo1--;
    while (zuo2 > zuo1 && minx[zuo2] > minx[i])
      box[minx[zuo2] - zuo2 + n + 1]--, zuo2--;
    ans = ans + box[maxx[i] - i + n + 1];
  }
  for (long long i = zuo2; i > zuo1; i--) box[minx[i] - i + n + 1]--;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long p, q;
    cin >> p >> q;
    a[p] = q;
  }
  dopart(1, n);
  cout << ans;
}
