#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
int n, m, x;
int K, jc[1000001];
int tp[1000001], t_cnt;
int tmp[1000001], tmp_cnt, intmp[1000001];
int sum[1000001];
int q[1000001], inq[1000001], qr;
map<int, int> pyc;
struct re {
  int a, b;
  bool operator()(const re &a, const re &b) { return a.b < b.b; }
};
vector<re> a[1000001];
int main() {
  jc[0] = 1;
  for (int i = 1; i <= 1000000; i++) jc[i] = (long long)jc[i - 1] * i % P;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &K);
    pyc.clear();
    for (int j = 1; j <= K; j++) {
      scanf("%d", &x);
      if (!inq[x]) {
        q[++qr] = x;
        inq[x] = 1;
      }
      pyc[x]++;
    }
    map<int, int>::iterator it = pyc.begin();
    tmp_cnt = 0;
    for (; it != pyc.end(); it++) {
      a[tp[it->first]].push_back((re){it->first, it->second});
      if (!intmp[tp[it->first]]) {
        tmp[++tmp_cnt] = tp[it->first];
        intmp[tp[it->first]] = 1;
      }
    }
    for (int j = 1; j <= tmp_cnt; j++) {
      sort(a[tmp[j]].begin(), a[tmp[j]].end(), re());
      for (int k = 0; k < a[tmp[j]].size(); k++) {
        int l;
        for (l = k;
             l + 1 < a[tmp[j]].size() && a[tmp[j]][l + 1].b == a[tmp[j]][l].b;
             l++)
          ;
        ++t_cnt;
        for (int ll = k; ll <= l; ll++) tp[a[tmp[j]][ll].a] = t_cnt;
        k = l;
      }
    }
    for (int j = 1; j <= tmp_cnt; j++) {
      a[tmp[j]].clear();
      intmp[tmp[j]] = 0;
    }
  }
  for (int i = 1; i <= qr; i++) sum[tp[q[i]]]++;
  int Ans = 1;
  for (int i = 1; i <= qr; i++) {
    Ans = (long long)Ans * jc[sum[tp[q[i]]]] % P;
    sum[tp[q[i]]] = 0;
  }
  Ans = (long long)Ans * jc[m - qr] % P;
  printf("%d\n", Ans);
  return 0;
}
