#include <bits/stdc++.h>
using namespace std;
int n, num[300007], t[1200007], tag[1200007], cnt[1200007], st1[300007],
    st2[300007], tp1, tp2;
long long res;
int read() {
  int num = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  return num;
}
int up(int w) {
  t[w] = min(t[2 * w], t[2 * w + 1]);
  cnt[w] = 0;
  if (t[2 * w] == t[w]) cnt[w] += cnt[2 * w];
  if (t[2 * w + 1] == t[w]) cnt[w] += cnt[2 * w + 1];
  return 0;
}
int down(int w) {
  if (!tag[w]) return 0;
  t[2 * w] += tag[w];
  t[2 * w + 1] += tag[w];
  tag[2 * w] += tag[w];
  tag[2 * w + 1] += tag[w];
  tag[w] = 0;
  return 0;
}
int mtree(int w, int l, int r) {
  if (l == r) {
    cnt[w] = 1;
    return 0;
  }
  int mid = (l + r) / 2;
  mtree(2 * w, l, mid);
  mtree(2 * w + 1, mid + 1, r);
  up(w);
  return 0;
}
int change(int w, int l, int r, int x, int y, int v) {
  if (x <= l && r <= y) {
    t[w] += v;
    tag[w] += v;
    return 0;
  }
  down(w);
  int mid = (l + r) / 2;
  if (x <= mid) change(2 * w, l, mid, x, y, v);
  if (y > mid) change(2 * w + 1, mid + 1, r, x, y, v);
  up(w);
  return 0;
}
pair<int, int> ask(int w, int l, int r, int x, int y) {
  if (x <= l && r <= y) return make_pair(t[w], cnt[w]);
  down(w);
  int mid = (l + r) / 2;
  if (x > mid) return ask(2 * w + 1, mid + 1, r, x, y);
  if (y <= mid) return ask(2 * w, l, mid, x, y);
  pair<int, int> a = ask(2 * w, l, mid, x, y),
                 b = ask(2 * w + 1, mid + 1, r, x, y);
  int res = min(a.first, b.first), tot = 0;
  if (a.first == res) tot += a.second;
  if (b.first == res) tot += b.second;
  return make_pair(res, tot);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    num[x] = y;
  }
  mtree(1, 1, n);
  for (int i = 1; i <= n; i++) {
    while (tp1 && num[st1[tp1]] < num[i]) {
      change(1, 1, n, st1[tp1 - 1] + 1, st1[tp1], -num[st1[tp1]]);
      tp1--;
    }
    st1[++tp1] = i;
    change(1, 1, n, st1[tp1 - 1] + 1, st1[tp1], num[st1[tp1]]);
    while (tp2 && num[st2[tp2]] > num[i]) {
      change(1, 1, n, st2[tp2 - 1] + 1, st2[tp2], num[st2[tp2]]);
      tp2--;
    }
    st2[++tp2] = i;
    change(1, 1, n, st2[tp2 - 1] + 1, st2[tp2], -num[st2[tp2]]);
    change(1, 1, n, 1, i, -1);
    pair<int, int> ret = ask(1, 1, n, 1, i);
    if (ret.first == -1) res += ret.second;
  }
  cout << res << endl;
  return 0;
}
