#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int n, a[MAXN], s1x[MAXN], s2x[MAXN], s1y[MAXN], s2y[MAXN], top1, top2;
long long ans;
struct node {
  long long mval, tag, cnt;
} t[MAXN << 2];
void build(int pos, int l, int r) {
  t[pos] = (node){l, 0, 1};
  if (l == r) return;
  int mid = l + (r - l) / 2;
  build(pos * 2, l, mid);
  build(pos * 2 + 1, mid + 1, r);
}
void spread_down(int pos) {
  t[pos * 2].mval += t[pos].tag;
  t[pos * 2].tag += t[pos].tag;
  t[pos * 2 + 1].mval += t[pos].tag;
  t[pos * 2 + 1].tag += t[pos].tag;
  t[pos].tag = 0;
}
void modify(int pos, int l, int r, int x, int y, int val) {
  if (x <= l && r <= y) {
    t[pos].mval += val;
    t[pos].tag += val;
    return;
  }
  spread_down(pos);
  int mid = l + (r - l) / 2;
  if (x <= mid) modify(pos * 2, l, mid, x, y, val);
  if (y >= mid + 1) modify(pos * 2 + 1, mid + 1, r, x, y, val);
  t[pos].mval = min(t[pos * 2].mval, t[pos * 2 + 1].mval);
  if (t[pos * 2].mval < t[pos * 2 + 1].mval) t[pos].cnt = t[pos * 2].cnt;
  if (t[pos * 2 + 1].mval < t[pos * 2].mval) t[pos].cnt = t[pos * 2 + 1].cnt;
  if (t[pos * 2].mval == t[pos * 2 + 1].mval)
    t[pos].cnt = t[pos * 2].cnt + t[pos * 2 + 1].cnt;
}
int query(int pos, int l, int r, int x, int y) {
  if (x <= l && r <= y) return t[pos].mval == 0 ? t[pos].cnt : 0;
  spread_down(pos);
  int mid = l + (r - l) / 2, tmp = 0;
  if (x <= mid) tmp += query(pos * 2, l, mid, x, y);
  if (y >= mid + 1) tmp += query(pos * 2 + 1, mid + 1, r, x, y);
  return tmp;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    a[x] = y;
  }
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    int x = i, y = a[i];
    modify(1, 1, n, 1, n, -1);
    while (top1 && s1y[top1] < y) {
      modify(1, 1, n, s1x[top1 - 1] + 1, s1x[top1], y - s1y[top1]);
      top1--;
    }
    s1x[++top1] = x;
    s1y[top1] = y;
    while (top2 && s2y[top2] > y) {
      modify(1, 1, n, s2x[top2 - 1] + 1, s2x[top2], s2y[top2] - y);
      top2--;
    }
    s2x[++top2] = x;
    s2y[top2] = y;
    ans += query(1, 1, n, 1, i);
  }
  cout << ans << endl;
}
