#include <bits/stdc++.h>
using namespace std;
template <class t>
inline void read(t& res) {
  char ch;
  while (ch = getchar(), !isdigit(ch))
    ;
  res = ch ^ 48;
  while (ch = getchar(), isdigit(ch)) res = res * 10 + (ch ^ 48);
}
const int e = 3e5 + 5, o = e << 1;
int a[e], b[e], n, val[e], cnt[o];
long long ans;
inline void solve(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1, i;
  solve(l, mid);
  solve(mid + 1, r);
  a[mid] = b[mid] = val[mid];
  a[mid + 1] = b[mid + 1] = val[mid + 1];
  for (i = mid - 1; i >= l; i--) {
    a[i] = max(a[i + 1], val[i]);
    b[i] = min(b[i + 1], val[i]);
  }
  for (i = mid + 2; i <= r; i++) {
    a[i] = max(a[i - 1], val[i]);
    b[i] = min(b[i - 1], val[i]);
  }
  for (i = l; i <= mid; i++) {
    int t = a[i] - b[i] + i;
    if (mid + 1 <= t && t <= r && a[t] <= a[i] && b[t] >= b[i]) {
      ans++;
    }
  }
  for (i = mid + 1; i <= r; i++) {
    int s = i + b[i] - a[i];
    if (l <= s && s <= mid && a[s] <= a[i] && b[s] >= b[i]) {
      ans++;
    }
  }
  int x = mid + 1, y = mid;
  for (i = mid; i >= l; i--) {
    while (x <= r && b[x] > b[i]) cnt[b[x] + x]--, x++;
    while (y < r && a[y + 1] <= a[i]) y++, cnt[b[y] + y]++;
    ans += max(cnt[a[i] + i], 0);
  }
  for (i = mid + 1; i <= r; i++) cnt[b[i] + i] = 0;
  x = mid;
  y = mid + 1;
  for (i = mid + 1; i <= r; i++) {
    while (x >= l && b[x] > b[i]) cnt[b[x] - x + n]--, x--;
    while (y > l && a[y - 1] <= a[i]) y--, cnt[b[y] - y + n]++;
    ans += max(cnt[a[i] - i + n], 0);
  }
  for (i = l; i <= mid; i++) cnt[b[i] - i + n] = 0;
}
int main() {
  read(n);
  int i, x;
  for (i = 1; i <= n; i++) read(x), read(val[x]);
  solve(1, n);
  cout << ans + n << endl;
  return 0;
}
