#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> L[1000005];   long long fac[1000005];   const long long MOD = 1000000007;   int main() {     int N, M;     scanf( %d%d , &N, &M);     for (int i = 0; i < N; ++i) {       int g;       scanf( %d , &g);       map<int, int> cnt;       for (int j = 0; j < g; ++j) {         int a;         scanf( %d , &a);         ++cnt[a];       }       for (auto x : cnt) {         L[x.first].push_back({i, x.second});       }     }     map<vector<pair<int, int>>, int> mp;     for (int i = 1; i <= M; ++i) ++mp[L[i]];     fac[0] = 1;     for (int i = 1; i <= M; ++i) fac[i] = (fac[i - 1] * i) % MOD;     long long ans = 1;     for (auto &x : mp) ans = (ans * fac[x.second]) % MOD;     printf( %I64d n , ans);   }   