#include #include #include #include #include #include #include #include using namespace std; int power(int x) { int result = 1; while(x > 0) { result *= 3; x--; } return result; } int main(){ int n, t; cin >> n >> t; vector a(n), b(n), c(n); for(int i = 0; i < t; i++) { cin >> a[i] >> b[i] >> c[i]; b[i]--; c[i]--; } long long result = 0; for(int mask = 0; mask < power(n); mask++) { string s = ""; int tmp = mask; while(tmp > 0) { s += (tmp % 3) + '0'; tmp /= 3; } while(s.size() < n) { s += "0"; } reverse(s.begin(), s.end()); bool ok = true; for(int j = 0; j < t; j++) { set st; for(int x = b[j]; x <= c[j]; x++) { if(s[x] == '0') { st.insert(0); } if(s[x] == '1') { st.insert(1); } if(s[x] == '2') { st.insert(3); } } if(st.size() != a[j]) { ok = false; } } if(ok) { result++; } } cout << result << endl; return 0; }