#include <bits/stdc++.h>
using namespace std;
int n, t1, t2, a[300005], s1[300005], s2[300005], t[300005 << 2],
    val[300005 << 2], tag[300005 << 2];
long long ans;
void up(int root) {
  t[root] = min(t[(root << 1)], t[(root << 1 | 1)]);
  val[root] = 0;
  if (t[(root << 1)] == t[root]) val[root] += val[(root << 1)];
  if (t[(root << 1 | 1)] == t[root]) val[root] += val[(root << 1 | 1)];
}
void down(int root) {
  if (!tag[root]) return;
  tag[(root << 1)] += tag[root];
  tag[(root << 1 | 1)] += tag[root];
  t[(root << 1)] += tag[root];
  t[(root << 1 | 1)] += tag[root];
  tag[root] = 0;
}
void build(int root, int l, int r) {
  if (l == r) {
    t[root] = l;
    val[root] = 1;
    return;
  }
  build((root << 1), l, ((l + r) >> 1));
  build((root << 1 | 1), ((l + r) >> 1) + 1, r);
  up(root);
}
void update(int root, int l, int r, int x, int y, int k) {
  if (l > y || r < x) return;
  if (l >= x && r <= y) {
    tag[root] += k;
    t[root] += k;
    return;
  }
  down(root);
  update((root << 1), l, ((l + r) >> 1), x, y, k);
  update((root << 1 | 1), ((l + r) >> 1) + 1, r, x, y, k);
  up(root);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x] = y;
  }
  build(1, 1, n);
  for (int i = 1; i <= n; ++i) {
    while (t1 >= 1 && a[s1[t1]] < a[i]) {
      update(1, 1, n, s1[t1 - 1] + 1, s1[t1], -a[s1[t1]]);
      t1--;
    }
    while (t2 >= 1 && a[s2[t2]] > a[i]) {
      update(1, 1, n, s2[t2 - 1] + 1, s2[t2], a[s2[t2]]);
      t2--;
    }
    update(1, 1, n, s1[t1] + 1, i, a[i]);
    update(1, 1, n, s2[t2] + 1, i, -a[i]);
    s1[++t1] = i;
    s2[++t2] = i;
    ans += val[1];
  }
  printf("%lld\n", ans);
}
