#include <bits/stdc++.h>
using namespace std;
const long long base[] = {126859, 145807};
const long long mod = 1000000007;
int n, m;
int a[100005], c[1000005];
pair<long long, long long> code[1000005];
long long fac[1000005];
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 1000000; i++) fac[i] = (fac[i - 1] * i) % mod;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) code[i] = pair<long long, long long>(0LL, 0LL);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &a[j]);
      c[a[j]]++;
    }
    for (int j = 1; j <= k; j++) {
      if (c[a[j]] > 0) {
        code[a[j]].first = code[a[j]].first * base[0] + (long long)i;
        code[a[j]].first = code[a[j]].first * base[0] + (long long)c[a[j]];
        code[a[j]].second = code[a[j]].second * base[1] + (long long)i;
        code[a[j]].second = code[a[j]].second * base[1] + (long long)c[a[j]];
        c[a[j]] = 0;
      }
    }
  }
  sort(code + 1, code + 1 + m);
  code[m + 1] = pair<long long, long long>(-2137182, 1821561);
  int cnt = 1;
  long long res = 1LL;
  for (int i = 2; i <= m + 1; i++) {
    if (code[i] != code[i - 1]) {
      res = (res * fac[cnt]) % mod;
      cnt = 0;
    }
    cnt++;
  }
  cout << res << endl;
  return 0;
}
