#include <bits/stdc++.h>
using namespace std;
struct segt {
  int rmin, lz, rcnt;
};
segt tree[1048596];
void pushdown(int l, int r, int index) {
  if (l > r) return;
  if (tree[index].lz != 0) {
    if (l != r) {
      tree[(index << 1)].lz += tree[index].lz;
      tree[(index << 1 | 1)].lz += tree[index].lz;
      tree[(index << 1)].rmin += tree[index].lz;
      tree[(index << 1 | 1)].rmin += tree[index].lz;
    }
    tree[index].lz = 0;
  }
}
segt pullup(segt t1, segt t2) {
  segt ret;
  ret.lz = 0;
  ret.rmin = min(t1.rmin, t2.rmin);
  ret.rcnt = (ret.rmin == t1.rmin) * t1.rcnt + (ret.rmin == t2.rmin) * t2.rcnt;
  return ret;
}
void build(int l, int r, int index) {
  if (l > r) return;
  if (l == r) {
    tree[index].rmin = l;
    tree[index].rcnt = 1;
    return;
  }
  build(l, ((l + r) >> 1), (index << 1));
  build(((l + r) >> 1) + 1, r, (index << 1 | 1));
  tree[index] = pullup(tree[(index << 1)], tree[(index << 1 | 1)]);
}
void update(int start, int end, int l, int r, int index, int val) {
  if (start > end || l > r || start > r || l > end) return;
  pushdown(l, r, index);
  if (start <= l && r <= end) {
    tree[index].rmin += val;
    tree[index].lz += val;
    return;
  }
  if (end <= ((l + r) >> 1)) {
    update(start, end, l, ((l + r) >> 1), (index << 1), val);
  } else if (start >= ((l + r) >> 1) + 1) {
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), val);
  } else {
    update(start, end, l, ((l + r) >> 1), (index << 1), val);
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), val);
  }
  tree[index] = pullup(tree[(index << 1)], tree[(index << 1 | 1)]);
}
segt query(int start, int end, int l, int r, int index) {
  if (start > end || l > r || start > r || l > end) return tree[0];
  pushdown(l, r, index);
  if (start <= l && r <= end) return tree[index];
  if (end <= ((l + r) >> 1))
    return query(start, end, l, ((l + r) >> 1), (index << 1));
  if (start >= ((l + r) >> 1) + 1)
    return query(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1));
  return pullup(query(start, end, l, ((l + r) >> 1), (index << 1)),
                query(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1)));
}
int a[1048596];
int n;
vector<pair<int, int>> mn, mx;
int main() {
  int i;
  long long ans = 0;
  scanf("%d", &n);
  build(1, n, 1);
  for (i = 1; i <= n; ++i) {
    int r, c;
    scanf("%d%d", &r, &c);
    a[r] = c;
  }
  mn.emplace_back(-10000000, 0);
  mx.emplace_back(10000000, 0);
  for (i = 1; i <= n; ++i) {
    while (a[i] <= mn.back().first) {
      int sz = mn.size();
      update(mn[sz - 2].second + 1, mn[sz - 1].second, 1, n, 1,
             mn[sz - 1].first);
      mn.pop_back();
    }
    update(mn.back().second + 1, i, 1, n, 1, -a[i]);
    mn.emplace_back(a[i], i);
    while (a[i] >= mx.back().first) {
      int sz = mx.size();
      update(mx[sz - 2].second + 1, mx[sz - 1].second, 1, n, 1,
             -mx[sz - 1].first);
      mx.pop_back();
    }
    update(mx.back().second + 1, i, 1, n, 1, a[i]);
    mx.emplace_back(a[i], i);
    auto ret = query(1, i, 1, n, 1);
    if (ret.rmin == i) {
      ans += ret.rcnt;
    }
  }
  cout << ans << endl;
  return 0;
}
