#include <bits/stdc++.h>
using namespace std;
long long hasha[1000100], hashb[1000100];
long long p1 = 1e9 + 123;
long long p2 = 1e9 + 181;
long long d = 10007;
map<pair<int, int>, int> mp;
int n, m;
long long fac[1000010];
int main() {
  scanf("%d%d", &n, &m);
  long long pp1 = 1, pp2 = 1;
  for (int i = 0; i < n; i++) {
    int temp, cnt;
    scanf("%d", &cnt);
    while (cnt--) {
      scanf("%d", &temp);
      hasha[temp] += pp1;
      hasha[temp] %= p1;
      hashb[temp] += pp2;
      hashb[temp] %= p2;
    }
    pp1 = (pp1 * d) % p1;
    pp2 = (pp2 * d) % p2;
  }
  for (int i = 1; i <= m; i++) mp[make_pair(hasha[i], hashb[i])]++;
  map<pair<int, int>, int>::iterator it = mp.begin();
  fac[0] = 1;
  long long ans = 1;
  for (int i = 1; i <= 1000000; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= 1000000007;
  }
  for (; it != mp.end(); it++) ans = (ans * fac[it->second]) % 1000000007;
  printf("%I64d\n", ans);
  return 0;
}
