#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define maxn 100010
#define mmaxn 1000000000
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pdd pair<double,double>
#define MOD 1000000007
#define f first
#define s second
using namespace std;
ll int factmod ( int n, ll int p ) {
ll int ans=1;
for(int i=1;i<=n;i++)
ans = (ans*i) %p;
return ans % p;
}
int main(){
ios_base::sync_with_stdio(0);
int n,m,g;
cin>>n>>m;
vector<string> poke(m+1,"");
for(int i=0;i<n;i++){
cin>>g;
vector<int> x(g);
map<int,int> y;
for(int j=0;j<g;j++){
cin>>x[i];
y[x[i]]++;
}
for(int j=1;j<=m;j++){
poke[j]+=to_string(y[j]);
}
}
map<string,int> z;
for(auto i:poke){
// cout<<i<<"\n";
int flag=0;
for(int j=0;j<i.length();j++){
if(i[j]!='0'){
flag=1;
break;
}
}
if(i!="" && flag==1)
z[i]++;
}
ll int ans=1;
for(auto i:z){
// cout<<i.f<<" "<<i.s<<"\n";
ans*= factmod(i.s,MOD);
ans%=MOD;
}
cout<<ans<<"\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbWF4biAxMDAwMTAKI2RlZmluZSBtbWF4biAxMDAwMDAwMDAwCiNkZWZpbmUgcGlpIHBhaXI8aW50LGludD4KI2RlZmluZSBwbGwgcGFpcjxsbCBpbnQsbGwgaW50PgojZGVmaW5lIHBkZCBwYWlyPGRvdWJsZSxkb3VibGU+CiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKI2RlZmluZSBmIGZpcnN0CiNkZWZpbmUgcyBzZWNvbmQKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbGwgaW50IGZhY3Rtb2QgKCBpbnQgbiwgbGwgaW50IHAgKSB7CglsbCBpbnQgYW5zPTE7CgkgZm9yKGludCBpPTE7aTw9bjtpKyspCiAgICAgICAgYW5zID0gKGFucyppKSA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