#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N], x, y, lz[4 * N];
vector<int> mx, mn;
struct node {
  int val, cnt;
} st[4 * N];
void push_down(int id, int l, int r) {
  if (lz[id] != 0) {
    st[id].val += lz[id];
    if (l < r) {
      lz[id << 1] += lz[id];
      lz[id << 1 | 1] += lz[id];
    }
    lz[id] = 0;
  }
}
node merge(node a, node b) {
  node res;
  if (a.val == b.val) {
    res.val = a.val;
    res.cnt = a.cnt + b.cnt;
  } else {
    if (a.val < b.val) {
      res = a;
    } else {
      res = b;
    }
  }
  return res;
}
void build(int id, int l, int r) {
  if (l > r) return;
  if (l == r) {
    st[id] = {1, 1};
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  st[id] = merge(st[id << 1], st[id << 1 | 1]);
}
void update(int id, int l, int r, int i, int j, int x) {
  push_down(id, l, r);
  if (l > j || r < i || i > j) {
    return;
  }
  if (l >= i && r <= j) {
    lz[id] += x;
    push_down(id, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update(id << 1, l, mid, i, j, x);
  update(id << 1 | 1, mid + 1, r, i, j, x);
  st[id] = merge(st[id << 1], st[id << 1 | 1]);
}
node get(int id, int l, int r, int i, int j) {
  push_down(id, l, r);
  if (l > j || r < i || i > j) {
    return {(int)1e9, 0};
  }
  if (l >= i && r <= j) {
    return st[id];
  }
  int mid = (l + r) >> 1;
  return merge(get(id << 1, l, mid, i, j), get(id << 1 | 1, mid + 1, r, i, j));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    a[x] = y;
  }
  long long ans = 0;
  mx.push_back(n + 1);
  mn.push_back(n + 1);
  build(1, 1, n);
  for (int i = n; i >= 1; i--) {
    int ptr = mx.size() - 1;
    while (mx.size() > 1 && a[i] > a[mx[ptr]]) {
      update(1, 1, n, mx[ptr], mx[ptr - 1] - 1, a[i] - a[mx[ptr]]);
      mx.pop_back();
      ptr = mx.size() - 1;
    }
    mx.push_back(i);
    ptr = mn.size() - 1;
    while (mn.size() > 1 && a[i] < a[mn[ptr]]) {
      update(1, 1, n, mn[ptr], mn[ptr - 1] - 1, a[mn[ptr]] - a[i]);
      mn.pop_back();
      ptr = mn.size() - 1;
    }
    mn.push_back(i);
    update(1, 1, n, i, n, -1);
    node tmp = get(1, 1, n, i, n);
    if (tmp.val == 0) {
      ans += tmp.cnt;
    }
  }
  cout << ans;
}
