#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 10;
int a[N], mn[4 * N], cnt[4 * N], lzy[4 * N], n;
stack<int> st, ts;
void build(int l = 1, int r = n + 1, int id = 1) {
  mn[id] = l;
  cnt[id] = 1;
  if (r - l == 1) return;
  int mid = (l + r) / 2;
  build(l, mid, 2 * id);
  build(mid, r, 2 * id + 1);
}
void shift(int id) {
  int x = lzy[id];
  mn[2 * id] += x;
  mn[2 * id + 1] += x;
  lzy[2 * id] += x;
  lzy[2 * id + 1] += x;
  lzy[id] = 0;
}
void upd(int l, int r, int x, int s = 1, int e = n + 1, int id = 1) {
  if (e <= l || r <= s) return;
  if (l <= s && e <= r) {
    mn[id] += x;
    lzy[id] += x;
    return;
  }
  shift(id);
  int mid = (s + e) / 2;
  upd(l, r, x, s, mid, 2 * id);
  upd(l, r, x, mid, e, 2 * id + 1);
  mn[id] = min(mn[2 * id], mn[2 * id + 1]);
  cnt[id] = 0;
  if (mn[id] == mn[2 * id]) cnt[id] += cnt[2 * id];
  if (mn[id] == mn[2 * id + 1]) cnt[id] += cnt[2 * id + 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x] = y;
  }
  build();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    upd(1, n + 1, -1);
    while ((int)(st.size()) && a[st.top()] < a[i]) {
      int r = st.top();
      st.pop();
      int l = ((int)(st.size()) ? st.top() : 0);
      upd(l + 1, r + 1, a[i] - a[r]);
    }
    st.push(i);
    while ((int)(ts.size()) && a[i] < a[ts.top()]) {
      int r = ts.top();
      ts.pop();
      int l = ((int)(ts.size()) ? ts.top() : 0);
      upd(l + 1, r + 1, a[r] - a[i]);
    }
    ts.push(i);
    if (mn[1] == 0) ans = ans + 1LL * cnt[1];
  }
  cout << ans;
  return 0;
}
