#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int g[1000010];
vector<int> st[1000010], in[1000010];
map<vector<int>, vector<int> > M;
int par[1000010], sz[1000010];
set<vector<int> > s;
long long int fact[1000010];
int root(int v) {
  if (par[v] == v) return v;
  return par[v] = root(par[v]);
}
void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  par[y] = x;
  sz[x] += sz[y];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int u;
      cin >> u;
      in[u].push_back(i);
      st[i].push_back(u);
    }
    sort(st[i].begin(), st[i].end());
  }
  for (int i = 1; i <= m; i++) {
    sort(in[i].begin(), in[i].end());
    s.insert(in[i]);
    M[in[i]].push_back(i);
  }
  for (int i = 0; i < 1000010; i++) par[i] = i, sz[i] = 1;
  for (set<vector<int> >::iterator itt = s.begin(); itt != s.end(); itt++) {
    vector<int> it = *itt;
    it = M[it];
    int cur = it[0];
    for (int j = 1; j < it.size(); j++) merge(cur, it[j]);
  }
  fact[0] = 1;
  for (int i = 1; i < 1000010; i++) fact[i] = 1LL * i * fact[i - 1] % mod;
  long long int ans = 1LL;
  for (int i = 0; i < 1000010; i++)
    if (root(i) == i) ans = 1LL * ans * fact[sz[i]] % mod;
  ans %= mod;
  if (ans < 0) ans += mod;
  cout << ans << endl;
}
