#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector l(n), r(n); for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; } vector p(n); iota(p.begin(), p.end(), 0); int ans = 0; do { int cur = 0; bool ok = true; for (int i : p) { if (cur > r[i]) { ok = false; break; } cur = max(cur, l[i]); } ans += ok; } while (next_permutation(p.begin(), p.end())); cout << ans << endl; }