#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, ans = 0; cin >> N; vector L(N), R(N), idx(N); for(int i=0; i> L[i] >> R[i]; iota(idx.begin(), idx.end(), 0); do { int x = 0; bool ok = true; for(int i=0; i R[idx[i]]) ok = false; x = max(x, L[idx[i]]); } ans += ok; } while(next_permutation(idx.begin(), idx.end())); cout << ans << endl; }