#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int N = 1 << 19;
int n;
int m;
pair<int, int> tree[2 * N + 10];
int same[2 * N + 10];
int p[N];
pair<int, int> sa[N];
pair<int, int> sb[N];
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first) return a;
  if (a.first > b.first) return b;
  return make_pair(a.first, a.second + b.second);
}
int build(int x, int l, int r) {
  tree[x] = make_pair(0, r - l + 1);
  same[x] = 0;
  if (l == r) return 0;
  int s = (l + r) / 2;
  build(x * 2 + 1, l, s);
  build(x * 2 + 2, s + 1, r);
  return 0;
}
int push(int x, int l, int r) {
  if (same[x]) {
    if (l != r) {
      same[x * 2 + 1] += same[x];
      same[x * 2 + 2] += same[x];
    }
    tree[x].first += same[x];
    same[x] = 0;
  }
  return 0;
}
pair<int, int> add(int x, int l, int r, int lc, int rc, int y) {
  push(x, l, r);
  if (r < lc || l > rc) return tree[x];
  if (l >= lc && r <= rc) {
    same[x] += y;
    push(x, l, r);
    return tree[x];
  }
  int s = (l + r) / 2;
  return tree[x] = merge(add(x * 2 + 1, l, s, lc, rc, y),
                         add(x * 2 + 2, s + 1, r, lc, rc, y));
}
pair<int, int> get(int x, int l, int r, int lc, int rc) {
  push(x, l, r);
  if (r < lc || l > rc) return make_pair(1e9, 0);
  if (l >= lc && r <= rc) return tree[x];
  int s = (l + r) / 2;
  return merge(get(x * 2 + 1, l, s, lc, rc), get(x * 2 + 2, s + 1, r, lc, rc));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    p[a] = b;
  }
  build(0, 0, n - 1);
  int a = 0, b = 0;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    add(0, 0, n - 1, i + 1, n - 1, -1);
    {
      int cur = 1;
      while (a > 0 && sa[a - 1].first < p[i]) {
        int tmp = sa[a - 1].second;
        add(0, 0, n - 1, i + cur, i + cur + tmp - 1, p[i] - sa[a - 1].first);
        cur += tmp;
        a--;
      }
      sa[a++] = make_pair(p[i], cur);
    }
    {
      int cur = 1;
      while (b > 0 && sb[b - 1].first > p[i]) {
        int tmp = sb[b - 1].second;
        add(0, 0, n - 1, i + cur, i + cur + tmp - 1, sb[b - 1].first - p[i]);
        cur += tmp;
        b--;
      }
      sb[b++] = make_pair(p[i], cur);
    }
    pair<int, int> res = get(0, 0, n - 1, i, n - 1);
    if (res.first == 0) ans += res.second;
  }
  cout << ans << endl;
  return 0;
}
