#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int maxn = 1e6 + 9;
const double pi = 3.14159265358979323846264;
const int inf = 2e9;
const long long mod = 1e9 + 7;
int op[maxn];
long long gh[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int num = 1;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    map<int, int> pq;
    map<int, vector<int> > io;
    pq.clear();
    io.clear();
    while (tmp--) {
      int jk;
      cin >> jk;
      ++pq[jk];
    }
    for (map<int, int>::iterator it = pq.begin(); it != pq.end(); ++it) {
      io[it->second].push_back(it->first);
    }
    for (map<int, vector<int> >::iterator it = io.begin(); it != io.end();
         ++it) {
      vector<int>& ui = it->second;
      map<int, vector<int> > jk;
      jk.clear();
      for (int j = 0; j < ui.size(); ++j) {
        jk[op[ui[j]]].push_back(ui[j]);
      }
      for (map<int, vector<int> >::iterator kl = jk.begin(); kl != jk.end();
           ++kl) {
        vector<int>& hj = kl->second;
        for (int j = 0; j < hj.size(); ++j) {
          op[hj[j]] = num;
        }
        ++num;
      }
    }
  }
  long long ans = 1;
  gh[0] = 1;
  for (int i = 1; i <= m; ++i) gh[i] = gh[i - 1] * i % mod;
  map<int, int> pq;
  pq.clear();
  for (int i = 1; i <= m; ++i) {
    ++pq[op[i]];
  }
  for (map<int, int>::iterator it = pq.begin(); it != pq.end(); ++it) {
    ans = ans * gh[it->second] % mod;
  }
  cout << ans;
  return 0;
}
