#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
typedef struct node2 {
  int lazyp;
  int cnt;
  int min;
} node1;
node1 tree[4 * N];
int a[N];
int up[N];
int down[N];
void initialise(int node, int b, int e) {
  if (b > e) {
    return;
  } else if (b == e) {
    tree[node].lazyp = 0;
    tree[node].cnt = 1;
    tree[node].min = b;
    return;
  } else {
    initialise(2 * node, b, (b + e) / 2);
    initialise(2 * node + 1, (b + e) / 2 + 1, e);
    tree[node].lazyp = 0;
    tree[node].cnt = 0;
    tree[node].min = INT_MAX;
    return;
  }
}
void update(int node, int b, int e, int i, int j, int val) {
  if (tree[node].lazyp != 0) {
    tree[node].min = tree[node].min + tree[node].lazyp;
    if (b != e) {
      tree[2 * node].lazyp = tree[2 * node].lazyp + tree[node].lazyp;
      tree[2 * node + 1].lazyp = tree[2 * node + 1].lazyp + tree[node].lazyp;
    }
    tree[node].lazyp = 0;
  }
  if (b > e || i > e || j < b) {
    return;
  } else if (i <= b && e <= j) {
    tree[node].min = tree[node].min + val;
    if (b != e) {
      tree[2 * node].lazyp = tree[2 * node].lazyp + val;
      tree[2 * node + 1].lazyp = tree[2 * node + 1].lazyp + val;
    }
    return;
  } else {
    update(2 * node, b, (b + e) / 2, i, j, val);
    update(2 * node + 1, (b + e) / 2 + 1, e, i, j, val);
    tree[node].min = min(tree[2 * node].min, tree[2 * node + 1].min);
    tree[node].cnt =
        (tree[node].min == tree[2 * node].min ? tree[2 * node].cnt : 0) +
        (tree[node].min == tree[2 * node + 1].min ? tree[2 * node + 1].cnt : 0);
    return;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    a[x] = y;
  }
  initialise(1, 0, n - 1);
  int cup = 1;
  int cdown = 1;
  up[0] = -1;
  down[0] = -1;
  long long int answer1 = 0;
  for (int i = 0; i < n; i++) {
    while (cup >= 2 && a[i] < a[up[cup - 1]]) {
      update(1, 0, n - 1, up[cup - 2] + 1, up[cup - 1], +a[up[cup - 1]]);
      cup--;
    }
    while (cdown >= 2 && a[i] > a[down[cdown - 1]]) {
      update(1, 0, n - 1, down[cdown - 2] + 1, down[cdown - 1],
             -a[down[cdown - 1]]);
      cdown--;
    }
    up[cup++] = i;
    down[cdown++] = i;
    update(1, 0, n - 1, up[cup - 2] + 1, up[cup - 1], -a[up[cup - 1]]);
    update(1, 0, n - 1, down[cdown - 2] + 1, down[cdown - 1],
           +a[down[cdown - 1]]);
    answer1 = answer1 + tree[1].cnt;
  }
  printf("%lld\n", answer1);
  return 0;
}
