#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 7;
int n, p[maxn];
int dpmin[maxn][20], dpmax[maxn][20];
int key = 300000;
int tong[900005];
void buildST() {
  for (int j = 0; j <= 20; ++j) {
    for (int i = 0; i < n && i + (1 << j) - 1 < n; ++i) {
      if (j == 0) {
        dpmin[i][j] = dpmax[i][j] = p[i];
      } else {
        dpmin[i][j] = min(dpmin[i + (1 << (j - 1))][j - 1], dpmin[i][j - 1]);
        dpmax[i][j] = max(dpmax[i + (1 << (j - 1))][j - 1], dpmax[i][j - 1]);
      }
    }
  }
}
int qmin(int l, int r) {
  int k = r - l + 1, t = 1, m = 0;
  while (t < k) {
    t *= 2;
    m++;
    if (t > k) m--;
  }
  return min(dpmin[l][m], dpmin[r + 1 - (1 << m)][m]);
}
int qmax(int l, int r) {
  int k = r - l + 1, t = 1, m = 0;
  while (t < k) {
    t *= 2;
    m++;
    if (t > k) m--;
  }
  return max(dpmax[l][m], dpmax[r + 1 - (1 << m)][m]);
}
int ans;
long long dfs(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  long long res = 0;
  int mid = (l + r) >> 1;
  for (int i = l; i <= mid; ++i) {
    int lmi = qmin(i, mid), lmx = qmax(i, mid);
    int pos_r = lmx - lmi + i;
    if (pos_r <= mid || pos_r > r) continue;
    if (qmin(mid + 1, pos_r) > qmin(i, mid) &&
        qmax(mid + 1, pos_r) < qmax(i, mid))
      res++;
  }
  for (int i = mid + 1; i <= r; ++i) {
    int rmi = qmin(mid + 1, i), rmx = qmax(mid + 1, i);
    int pos_l = i - (rmx - rmi);
    if (pos_l > mid || pos_l < l) continue;
    if (qmin(pos_l, mid) > qmin(mid + 1, i) &&
        qmax(pos_l, mid) < qmax(mid + 1, i))
      res++;
  }
  int r1 = mid + 1, r2 = mid + 1;
  for (int i = mid; i >= l; --i) {
    while (r2 <= r && qmin(mid + 1, r2) > qmin(i, mid)) {
      tong[key + qmax(mid + 1, r2) - r2]++;
      r2++;
    }
    while (qmax(mid + 1, r1) < qmax(i, mid)) {
      tong[key + qmax(mid + 1, r1) - r1]--;
      r1++;
      if (r1 > r) break;
    }
    if (r1 > r) break;
    if (r1 < r2) res += tong[key + qmin(i, mid) - i];
  }
  for (int i = mid + 1; i <= r; ++i) tong[key + qmax(mid + 1, i) - i] = 0;
  r1 = mid + 1, r2 = mid + 1;
  for (int i = mid; i >= l; --i) {
    while (r2 <= r && qmax(mid + 1, r2) < qmax(i, mid)) {
      tong[key + qmin(mid + 1, r2) + r2]++;
      r2++;
    }
    while (qmin(mid + 1, r1) > qmin(i, mid)) {
      tong[key + qmin(mid + 1, r1) + r1]--;
      r1++;
      if (r1 > r) break;
    }
    if (r1 > r) break;
    if (r1 < r2) res += tong[key + qmax(i, mid) + i];
  }
  for (int i = mid + 1; i <= r; ++i) tong[key + qmin(mid + 1, i) + i] = 0;
  return res + dfs(l, mid) + dfs(mid + 1, r);
}
int main() {
  scanf("%d", &n);
  int x, y;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x, &y);
    p[x - 1] = y;
  }
  buildST();
  printf("%I64d\n", dfs(0, n - 1));
  return 0;
}
