#include <bits/stdc++.h>
using namespace std;
unsigned long long hash1[1000005], hash2[1000005], cnt[1000005], fact[1000005];
map<pair<unsigned long long int,
         pair<unsigned long long int, unsigned long long int> >,
    int>
    X;
void precal() {
  fact[0] = 1;
  int i;
  for (i = 1; i <= 1000000; i++) fact[i] = i * fact[i - 1] % 1000000007;
}
int main() {
  precal();
  int i, N, M, j;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= N; i++) {
    int x;
    scanf("%d", &x);
    for (j = 1; j <= x; j++) {
      int type;
      scanf("%d", &type);
      hash1[type] = hash1[type] * 1000003 + i;
      hash2[type] = hash2[type] * 1000007 + i;
      cnt[type]++;
    }
  }
  for (i = 1; i <= M; i++) {
    X[make_pair(cnt[i], make_pair(hash1[i], hash2[i]))]++;
  }
  long long ans = 1;
  for (map<pair<unsigned long long int,
                pair<unsigned long long int, unsigned long long int> >,
           int>::iterator it = X.begin();
       it != X.end(); it++) {
    ans = ans * fact[it->second] % 1000000007;
  }
  printf("%lld", ans);
}
