#include <bits/stdc++.h>
using namespace std;
const int NUM = 1000010;
int n, m;
int g, t[NUM];
int mod = 1e9 + 7;
int id[NUM], tot = 0;
int cnt[NUM];
int a[NUM], h;
bool cmp(int i, int j) {
  if (id[i] == id[j]) return cnt[i] < cnt[j];
  return id[i] < id[j];
}
void solve() {
  sort(a, a + h, cmp);
  for (int i = 0, j; i < h;) {
    for (j = i; j < h && id[a[i]] == id[a[j]] && cnt[a[i]] == cnt[a[j]]; ++j)
      ;
    for (++tot; i < j; ++i) id[a[i]] = tot;
  }
}
int fact[NUM];
int main() {
  scanf("%d%d", &n, &m);
  fact[0] = 1;
  for (int i = 1; i <= m; ++i) fact[i] = 1ll * fact[i - 1] * i % mod;
  tot = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &g);
    for (int j = 0; j < g; ++j) {
      scanf("%d", &t[j]);
    }
    h = 0;
    for (int j = 0; j < g; ++j) {
      if (cnt[t[j]] == 0) a[h++] = t[j];
      ++cnt[t[j]];
    }
    solve();
    for (int j = 0; j < g; ++j) {
      --cnt[t[j]];
    }
  }
  unordered_map<int, int> num;
  for (int i = 1; i <= m; ++i) {
    num[id[i]]++;
  }
  int ans = 1;
  for (auto p : num) {
    ans = 1ll * ans * fact[p.second] % mod;
  }
  printf("%d\n", ans);
  return 0;
}
