#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector> v(n); rep(i, n) cin >> v[i].first >> v[i].second; int ans = 0; vector p(n); iota(p.begin(), p.end(), 0); do { bool ok = true; int maxim = 0; rep(i, n - 1) { maxim = max(maxim, v[p[i]].first); if (maxim > v[p[i + 1]].second) ok = false; } if (ok) ans++; } while (next_permutation(p.begin(), p.end())); cout << ans << '\n'; return 0; }