#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int lazy;
  pair<long long int, long long int> ans;
};
const long long int maxn = 300300;
long long int N, ar[maxn], at1, at2, ans;
pair<long long int, long long int> stmx[maxn], stmn[maxn];
class segment_tree {
 public:
  node sgm[4 * maxn];
  void fill() {
    for (long long int i = 1; i <= 1200000; i++) sgm[i].ans.first = 1e9;
  }
  pair<long long int, long long int> f(long long int k) {
    return pair<long long int, long long int>(sgm[k].ans.first + sgm[k].lazy,
                                              sgm[k].ans.second);
  }
  pair<long long int, long long int> nw(long long int k, long long int b,
                                        long long int s, long long int x) {
    if (x < b || x > s) return f(k);
    if (b == s) {
      sgm[k].ans = pair<long long int, long long int>(0, 1);
      return f(k);
    }
    long long int m = (b + s) >> 1;
    pair<long long int, long long int> a = nw(k + k, b, m, x);
    pair<long long int, long long int> c = nw(k + k + 1, m + 1, s, x);
    if (a.first == c.first) a.second += c.second, c.second = 1e9;
    sgm[k].ans = min(a, c);
    return f(k);
  }
  pair<long long int, long long int> upd(long long int k, long long int b,
                                         long long int s, long long int x,
                                         long long int y, long long int z) {
    if (x <= b && s <= y) {
      sgm[k].lazy += z;
      return f(k);
    }
    if (x > s || b > y) return f(k);
    long long int m = (b + s) >> 1;
    pair<long long int, long long int> a = upd(k + k, b, m, x, y, z);
    pair<long long int, long long int> c = upd(k + k + 1, m + 1, s, x, y, z);
    if (a.first == c.first) a.second += c.second, c.second = 1e9;
    sgm[k].ans = min(a, c);
    return f(k);
  }
  long long int getzeros() {
    if (!sgm[1].ans.first) return sgm[1].ans.second;
    return 0;
  }
} seg;
int main() {
  scanf("%lld", &N);
  for (long long int i = 1; i <= N; i++) {
    long long int a, b;
    scanf("%lld %lld", &a, &b);
    ar[a] = b;
  }
  seg.fill();
  stmn[++at1] = pair<long long int, long long int>(0, 0);
  stmn[++at2] = pair<long long int, long long int>(1e9, 0);
  for (long long int j = 1; j <= N; j++) {
    seg.nw(1, 1, N, j);
    while (at1 > 1 && stmn[at1].first > ar[j]) {
      seg.upd(1, 1, N, stmn[at1 - 1].second + 1, stmn[at1].second,
              stmn[at1].first - ar[j]);
      at1--;
    }
    stmn[++at1] = pair<long long int, long long int>(ar[j], j);
    while (at2 > 1 && stmx[at2].first < ar[j]) {
      seg.upd(1, 1, N, stmx[at2 - 1].second + 1, stmx[at2].second,
              ar[j] - stmx[at2].first);
      at2--;
    }
    stmx[++at2] = pair<long long int, long long int>(ar[j], j);
    seg.upd(1, 1, N, 1, j - 1, -1);
    ans += seg.getzeros();
  }
  printf("%lld\n", ans);
  return 0;
}
