#include <bits/stdc++.h>
using namespace std;
namespace Program {
const int N = (int)3e5;
int n;
int a[N + 5];
void input() {
  scanf("%d", &n);
  for (int i = 0, i_END_ = n; i < i_END_; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    a[x] = y;
  }
}
long long ans;
int lmi[N + 5], lmx[N + 5];
int rmi[N + 5], rmx[N + 5];
int cnt[N * 2 + 5];
void conquer(int l, int r) {
  int mid = l + (r - l) / 2;
  assert(l < mid);
  assert(mid < r);
  lmi[mid - 1] = lmx[mid - 1] = a[mid - 1];
  for (int i = (mid - 1) - 1, i_BEGIN_ = l; i >= i_BEGIN_; --i)
    lmi[i] = min(lmi[i + 1], a[i]), lmx[i] = max(lmx[i + 1], a[i]);
  rmi[mid] = rmx[mid] = a[mid];
  for (int i = mid + 1, i_END_ = r; i < i_END_; ++i)
    rmi[i] = min(rmi[i - 1], a[i]), rmx[i] = max(rmx[i - 1], a[i]);
  for (int i = l, i_END_ = mid; i < i_END_; ++i) {
    int pos = i + lmx[i] - lmi[i];
    if (mid <= pos && pos < r) ans += rmx[pos] <= lmx[i] && rmi[pos] >= lmi[i];
  }
  for (int i = mid, i_END_ = r; i < i_END_; ++i) {
    int pos = i - (rmx[i] - rmi[i]);
    if (l <= pos && pos < mid) ans += lmx[pos] <= rmx[i] && lmi[pos] >= rmi[i];
  }
  int mip = mid, mxp = mid;
  for (int i = (mid)-1, i_BEGIN_ = l; i >= i_BEGIN_; --i) {
    while (mip < r && lmi[i] <= rmi[mip]) cnt[rmx[mip] - mip + N]++, ++mip;
    while (mxp < r && !(lmx[i] <= rmx[mxp])) cnt[rmx[mxp] - mxp + N]--, ++mxp;
    if (mxp < mip) ans += cnt[lmi[i] - i + N];
  }
  for (int i = mid, i_END_ = r; i < i_END_; ++i) cnt[rmx[i] - i + N] = 0;
  mip = mxp = mid;
  for (int i = (mid)-1, i_BEGIN_ = l; i >= i_BEGIN_; --i) {
    while (mxp < r && lmx[i] >= rmx[mxp]) cnt[rmi[mxp] + mxp]++, ++mxp;
    while (mip < r && !(lmi[i] >= rmi[mip])) cnt[rmi[mip] + mip]--, ++mip;
    if (mip < mxp) ans += cnt[lmx[i] + i];
  }
  for (int i = mid, i_END_ = r; i < i_END_; ++i) cnt[rmi[i] + i] = 0;
}
void divide(int l, int r) {
  if (r - l < 2) {
    ++ans;
    return;
  }
  conquer(l, r);
  int mid = l + (r - l) / 2;
  divide(l, mid);
  divide(mid, r);
}
void solve() {
  ans = 0;
  memset(cnt, 0, sizeof cnt);
  divide(0, n);
  cout << ans << endl;
}
}  // namespace Program
int main() {
  Program::input();
  Program::solve();
  return 0;
}
