#include <bits/stdc++.h>
using namespace std;
const int maxN = 100000 + 10, maxM = 1000000 + 10;
const int MOD = int(1e9 + 7);
const int BB[4] = {3, 5, 7, 11};
int n, m;
map<vector<int>, int> ma;
long long V[maxM][4], fac[maxM];
int main() {
  scanf("%d%d", &n, &m);
  memset(V, 0, sizeof V);
  long long Z[4] = {1, 1, 1, 1};
  int gr = 0;
  for (int i = 0; i < n; i++) {
    int g, u;
    scanf("%d", &g);
    map<int, int> S;
    while (g--) {
      scanf("%d", &u);
      S[u]++;
    }
    map<int, vector<int> > G;
    for (auto p : S) {
      G[p.second].push_back(p.first);
    }
    for (auto p : G) {
      for (int u : p.second) {
        for (int z = 0; z < 4; z++) {
          V[u][z] = (V[u][z] + Z[z]) % MOD;
        }
      }
      for (int z = 0; z < 4; z++) {
        Z[z] = (Z[z] * BB[z]) % MOD;
      }
    }
  }
  fac[0] = 1;
  for (int i = 1; i <= m; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    vector<int> Q;
    for (int z = 0; z < 4; z++) Q.push_back((int)V[i][z]);
    ma[Q]++;
  }
  int res = 1;
  for (auto p : ma) {
    res = (1LL * res * fac[p.second]) % MOD;
  }
  printf("%d\n", res);
  return 0;
}
