#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = int(3e5) + 100;
struct tr {
  int min_val, cnt, add, l, r;
  tr() {}
  tr(int min_val, int cnt) : min_val(min_val), cnt(cnt) {}
};
int maxv;
int a[N];
pair<int, int> st_min[N], st_max[N];
tr rmq[4 * N];
inline void merge(const tr& a, const tr& b, tr& c) {
  if (a.min_val == b.min_val) {
    c.min_val = a.min_val;
    c.cnt = a.cnt + b.cnt;
    return;
  }
  if (a.min_val < b.min_val) {
    c.min_val = a.min_val;
    c.cnt = a.cnt;
    return;
  }
  c.min_val = b.min_val;
  c.cnt = b.cnt;
}
inline void push(int v) {
  if (rmq[v].add == 0) {
    return;
  }
  rmq[v].min_val += rmq[v].add;
  if (v < maxv) {
    rmq[v * 2].add += rmq[v].add;
    rmq[v * 2 + 1].add += rmq[v].add;
  }
  rmq[v].add = 0;
}
inline void calc(int v) { merge(rmq[v * 2], rmq[v * 2 + 1], rmq[v]); }
void set_val(int v, int pos, int val) {
  push(v);
  if (rmq[v].l > pos || rmq[v].r < pos) {
    return;
  }
  if (v >= maxv) {
    rmq[v].min_val = val;
    rmq[v].cnt = 1;
    return;
  }
  set_val(v * 2, pos, val);
  set_val(v * 2 + 1, pos, val);
  calc(v);
}
void update(int v, int l, int r, int add) {
  push(v);
  if (rmq[v].l > r || rmq[v].r < l) {
    return;
  }
  if (rmq[v].l >= l && rmq[v].r <= r) {
    rmq[v].add += add;
    push(v);
    return;
  }
  update(v * 2, l, r, add);
  update(v * 2 + 1, l, r, add);
  calc(v);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int r, c;
    scanf("%d %d", &r, &c);
    --r;
    --c;
    a[r] = c;
  }
  maxv = 1;
  while (maxv < n) {
    maxv *= 2;
  }
  for (int i = 0; i < maxv; ++i) {
    rmq[i + maxv].min_val = inf;
    rmq[i + maxv].cnt = 1;
    rmq[i + maxv].l = rmq[i + maxv].r = i;
  }
  for (int i = maxv - 1; i > 0; --i) {
    merge(rmq[i * 2], rmq[i * 2 + 1], rmq[i]);
    rmq[i].l = rmq[i * 2].l;
    rmq[i].r = rmq[i * 2 + 1].r;
  }
  int sz_min = 1;
  st_min[0] = make_pair(-inf, -1);
  int sz_max = 1;
  st_max[0] = make_pair(inf, -1);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    set_val(1, i, i);
    int pos = i;
    while (sz_min > 0 && st_min[sz_min - 1].first >= a[i]) {
      int npos = st_min[--sz_min].second;
      update(1, npos, pos - 1, st_min[sz_min].first - a[i]);
      pos = npos;
    }
    st_min[sz_min++] = make_pair(a[i], pos);
    pos = i;
    while (sz_max > 0 && st_max[sz_max - 1].first <= a[i]) {
      int npos = st_max[--sz_max].second;
      update(1, npos, pos - 1, a[i] - st_max[sz_max].first);
      pos = npos;
    }
    st_max[sz_max++] = make_pair(a[i], pos);
    if (rmq[1].min_val == i) {
      ans += rmq[1].cnt;
    }
  }
  cout << ans << endl;
  return 0;
}
