#include <bits/stdc++.h>
using namespace std;
int prime1 = 2473;
int prime2 = 7919;
long long MOD = 1000000007;
long long hash1[1000005], hash2[1000006], fac[1000006];
int main() {
  fac[0] = 1;
  for (int i = 1; i < 1000001; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
  }
  int n;
  cin >> n;
  int m;
  cin >> m;
  long long po1 = 1, po2 = 1;
  for (int i = 0; i < n; i++) {
    int g;
    scanf("%d", &g);
    map<int, int> cnt;
    for (int j = 0; j < g; j++) {
      int t;
      scanf("%d", &t);
      t--;
      auto it = cnt.find(t);
      if (it == cnt.end())
        cnt[t] = 1;
      else
        it->second++;
    }
    map<int, int> rcnt;
    int p = 1;
    for (auto& it : cnt) {
      int c = it.second;
      int grp = p;
      auto itt = rcnt.find(c);
      if (itt == rcnt.end())
        rcnt[c] = p++;
      else
        grp = itt->second;
      int t = it.first;
      hash1[t] = hash1[t] + po1 * grp;
      hash2[t] = hash2[t] + po2 * grp;
    }
    po1 *= prime1;
    po2 *= prime2;
  }
  map<pair<long long, long long>, int> cnt;
  for (int t = 0; t < m; t++) {
    pair<int, int> pii = {hash1[t], hash2[t]};
    auto it = cnt.find(pii);
    if (it == cnt.end())
      cnt[pii] = 1;
    else
      it->second++;
  }
  long long ans = 1;
  for (auto& p : cnt) {
    ans = (ans * fac[p.second]) % MOD;
  }
  cout << ans;
  return 0;
}
