#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int MAX = 3e5;
const int INF = 1e9;
int n;
int a[MAXN];
int leftMin[MAXN], leftMax[MAXN], rightMin[MAXN], rightMax[MAXN],
    diff[2 * MAXN];
long long sol;
void rek(int lo, int hi) {
  if (lo == hi) {
    sol++;
    return;
  }
  int mid = (lo + hi) >> 1;
  leftMin[mid] = leftMax[mid] = a[mid];
  rightMin[mid + 1] = rightMax[mid + 1] = a[mid + 1];
  for (int i = mid - 1; i >= lo; --i) {
    leftMin[i] = min(leftMin[i + 1], a[i]);
    leftMax[i] = max(leftMax[i + 1], a[i]);
  }
  for (int i = mid + 2; i <= hi; ++i) {
    rightMin[i] = min(rightMin[i - 1], a[i]);
    rightMax[i] = max(rightMax[i - 1], a[i]);
  }
  for (int i = mid; i >= lo; --i) {
    int difference = leftMax[i] - leftMin[i];
    if (i + difference > mid && i + difference <= hi &&
        rightMin[i + difference] > leftMin[i] &&
        rightMax[i + difference] < leftMax[i])
      sol++;
  }
  for (int i = mid + 1; i <= hi; ++i) {
    int difference = rightMax[i] - rightMin[i];
    if (i - difference >= lo && i - difference <= mid &&
        leftMin[i - difference] > rightMin[i] &&
        leftMax[i - difference] < rightMax[i])
      sol++;
  }
  int pos = mid + 1, loPos = -1, loCnt = 0;
  vector<int> v;
  for (int i = mid; i >= lo; --i) {
    while (pos != hi + 1 && leftMax[i] > rightMax[pos]) pos++;
    while (loCnt < ((int)v.size()) && leftMax[i] > rightMax[loPos]) {
      diff[v[loCnt]]--;
      loPos++;
      loCnt++;
      if (loCnt == ((int)v.size())) loPos = -1;
    }
    if (pos == hi + 1 && leftMax[i] > rightMax[pos - 1]) break;
    while (pos != hi + 1 && leftMin[i] < rightMin[pos] &&
           leftMax[i] < rightMax[pos]) {
      diff[rightMax[pos] - pos + MAX]++;
      v.push_back(rightMax[pos] - pos + MAX);
      if (loPos == -1) loPos = pos;
      pos++;
    }
    if (leftMin[i] < rightMin[pos - 1] && pos != mid + 1) {
      sol += diff[leftMin[i] - i + MAX];
    }
  }
  for (int i = loCnt; i < ((int)v.size()); ++i) diff[v[i]]--;
  v.clear();
  pos = mid + 1, loPos = -1, loCnt = 0;
  for (int i = mid; i >= lo; --i) {
    while (pos != hi + 1 && leftMin[i] < rightMin[pos]) pos++;
    while (loCnt < ((int)v.size()) && leftMin[i] < rightMin[loPos]) {
      diff[v[loCnt]]--;
      loPos++;
      loCnt++;
      if (loCnt == ((int)v.size())) loPos = -1;
    }
    if (pos == hi + 1 && leftMin[i] < rightMin[pos - 1]) break;
    while (pos != hi + 1 && leftMin[i] > rightMin[pos] &&
           leftMax[i] > rightMax[pos]) {
      diff[rightMin[pos] + pos]++;
      v.push_back(rightMin[pos] + pos);
      if (loPos == -1) loPos = pos;
      pos++;
    }
    if (leftMax[i] > rightMax[pos - 1] && pos != mid + 1) {
      sol += diff[leftMax[i] + i];
    }
  }
  for (int i = loCnt; i < ((int)v.size()); ++i) diff[v[i]]--;
  v.clear();
  rek(lo, mid);
  rek(mid + 1, hi);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    a[x] = y;
  }
  rek(0, n - 1);
  cout << sol;
}
