#include <bits/stdc++.h>
using namespace std;
int mod;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long x, long long y) {
  while (y) {
    long long t = x % y;
    x = y;
    y = t;
  }
  return x;
}
long long inv(long long x) { return powmod(x, mod - 2); }
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int mi[300010 << 2], lazy[300010 << 2], cnt[300010 << 2];
int n, a[300010];
void build(int ll, int rr, int rt) {
  mi[rt] = ll, lazy[rt] = 0, cnt[rt] = 1;
  if (ll == rr) return;
  build(ll, ((ll + rr) / 2), (rt << 1));
  build(((ll + rr) / 2) + 1, rr, ((rt << 1) | 1));
}
void push_down(int rt) {
  if (lazy[rt] != 0) {
    lazy[(rt << 1)] += lazy[rt];
    lazy[((rt << 1) | 1)] += lazy[rt];
    lazy[rt] = 0;
  }
}
void push_up(int rt) {
  int x = lazy[(rt << 1)] + mi[(rt << 1)];
  int y = lazy[((rt << 1) | 1)] + mi[((rt << 1) | 1)];
  mi[rt] = x < y ? x : y;
  cnt[rt] = (x == mi[rt] ? cnt[(rt << 1)] : 0) +
            (y == mi[rt] ? cnt[((rt << 1) | 1)] : 0);
}
void modify(int ll, int rr, int rt, int l, int r, int v) {
  if (ll == l && rr == r) {
    lazy[rt] += v;
    return;
  }
  push_down(rt);
  if (r <= ((ll + rr) / 2))
    modify(ll, ((ll + rr) / 2), (rt << 1), l, r, v);
  else if (l > ((ll + rr) / 2))
    modify(((ll + rr) / 2) + 1, rr, ((rt << 1) | 1), l, r, v);
  else
    modify(ll, ((ll + rr) / 2), (rt << 1), l, ((ll + rr) / 2), v),
        modify(((ll + rr) / 2) + 1, rr, ((rt << 1) | 1), ((ll + rr) / 2) + 1, r,
               v);
  push_up(rt);
}
int up[300010], down[300010], uptop, downtop;
int main() {
  n = read();
  a[0] = 0;
  uptop = downtop = 1;
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    a[x] = y;
  }
  build(1, n, 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    while (uptop >= 2 && a[i] < a[up[uptop - 1]]) {
      modify(1, n, 1, up[uptop - 2] + 1, up[uptop - 1], a[up[uptop - 1]]);
      uptop--;
    }
    while (downtop >= 2 && a[i] > a[down[downtop - 1]]) {
      modify(1, n, 1, down[downtop - 2] + 1, down[downtop - 1],
             -a[down[downtop - 1]]);
      downtop--;
    }
    up[uptop++] = i;
    down[downtop++] = i;
    modify(1, n, 1, up[uptop - 2] + 1, up[uptop - 1], -a[i]);
    modify(1, n, 1, down[downtop - 2] + 1, i, a[i]);
    ans += cnt[1];
  }
  printf("%lld\n", ans);
  return 0;
}
