#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp& x) {
  x = 0;
  char tmp;
  bool key = 0;
  for (tmp = getchar(); !isdigit(tmp); tmp = getchar()) key = (tmp == '-');
  for (; isdigit(tmp); tmp = getchar()) x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x, tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x, tp y) {
  x = x < y ? y : x;
}
const int N = 300010;
int n, per[N];
struct node {
  int mn, num, tag;
} t[N << 2];
void puttag(int x, int v) {
  t[x].mn += v;
  t[x].tag += v;
}
void push_down(int x) {
  if (t[x].tag) {
    puttag(x << 1, t[x].tag);
    puttag(x << 1 | 1, t[x].tag);
    t[x].tag = 0;
  }
}
void push_up(int x) {
  t[x].mn = min(t[x << 1].mn, t[x << 1 | 1].mn);
  t[x].num = 0;
  if (t[x << 1].mn == t[x].mn) t[x].num += t[x << 1].num;
  if (t[x << 1 | 1].mn == t[x].mn) t[x].num += t[x << 1 | 1].num;
}
void modify(int l, int r, int v, int x = 1, int lp = 1, int rp = n) {
  if (l > rp || lp > r) return;
  if (lp >= l && rp <= r) {
    puttag(x, v);
    return;
  }
  int mid = (lp + rp) >> 1;
  push_down(x);
  modify(l, r, v, x << 1, lp, mid);
  modify(l, r, v, x << 1 | 1, mid + 1, rp);
  push_up(x);
}
int query(int l, int r, int x = 1, int lp = 1, int rp = n) {
  if (l > rp || lp > r) return 0;
  if (lp >= l && rp <= r) {
    if (t[x].mn == -1)
      return t[x].num;
    else
      return 0;
  }
  int mid = (lp + rp) >> 1;
  push_down(x);
  return query(l, r, x << 1, lp, mid) + query(l, r, x << 1 | 1, mid + 1, rp);
}
void build(int x = 1, int lp = 1, int rp = n) {
  if (lp == rp) {
    t[x].num = 1;
    return;
  }
  int mid = (lp + rp) >> 1;
  build(x << 1, lp, mid);
  build(x << 1 | 1, mid + 1, rp);
  push_up(x);
}
vector<pair<int, int> > sta[2];
int main() {
  int x, y;
  long long ans = 0;
  read(n);
  for (int i = (1); i <= (n); ++i) {
    read(x), read(y);
    per[x] = y;
  }
  build();
  for (int i = (1); i <= (n); ++i) {
    modify(1, i, -1);
    {
      int lp = i, v = per[i];
      while (!sta[0].empty() && sta[0].back().first <= v) {
        modify(sta[0].back().second, lp - 1, -sta[0].back().first);
        lp = sta[0].back().second;
        sta[0].pop_back();
      }
      sta[0].push_back(pair<int, int>(v, lp));
      modify(lp, i, v);
    }
    {
      int lp = i, v = per[i];
      while (!sta[1].empty() && sta[1].back().first >= v) {
        modify(sta[1].back().second, lp - 1, sta[1].back().first);
        lp = sta[1].back().second;
        sta[1].pop_back();
      }
      sta[1].push_back(pair<int, int>(v, lp));
      modify(lp, i, -v);
    }
    ans += query(1, i);
  }
  cout << ans << endl;
  return 0;
}
