#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> a(n); for(auto &&[l, r] : a) cin >> l >> r; vector ord(n); iota(ord.begin(), ord.end(), 0); int ans = 0; do{ int v = 0; for(auto idx : ord){ auto [l, r] = a[idx]; if(v > r){ v = -1; break; } v = max(v, l); } ans += (v != -1); }while(next_permutation(ord.begin(), ord.end())); cout << ans << '\n'; }