#include <bits/stdc++.h>
using namespace std;
const int maxM = 1000100;
int N, M;
int d[maxM], K;
int main() {
  scanf("%d%d", &N, &M);
  K = 1;
  while (N--) {
    static int q[maxM];
    int l;
    scanf("%d", &l);
    for (int i = 0; i < l; i++) scanf("%d", q + i), q[i]--;
    sort(q, q + l);
    static pair<int, int> r[maxM];
    int s = 0;
    for (int i = 0; i < l;) {
      int j = i + 1;
      while (j < l && q[j] == q[i]) j++;
      r[s++] = pair<int, int>(j - i, q[i]);
      i = j;
    }
    sort(r, r + s);
    for (int i = 0; i < s;) {
      int j = i + 1;
      while (j < s && r[i].first == r[j].first) j++;
      for (int k = i; k < j; k++) {
        r[k].first = d[r[k].second];
      }
      sort(r + i, r + j);
      for (int k = i; k < j;) {
        int p = k + 1;
        while (p < j && r[p].first == r[k].first) p++;
        for (int t = k; t < p; t++) d[r[t].second] = K;
        K++;
        k = p;
      }
      i = j;
    }
  }
  sort(d, d + M);
  long long ans = 1;
  for (int i = 0; i < M;) {
    int j = i + 1;
    while (j < M && d[j] == d[i]) j++;
    for (int k = 2; k <= j - i; k++) ans = ans * k % 1000000007;
    i = j;
  }
  cout << ans << endl;
  return 0;
}
