#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
int val[2][MAXN];
const int MOD[] = {1000000007, 1000000009};
const int QTD = 2;
const int B = 97;
int powers[2][MAXN];
int fact[MAXN];
int main() {
  int n, m;
  scanf(" %d %d", &(n), &(m));
  for (int i = 0; i < (QTD); ++i) {
    powers[i][0] = 1;
    for (int j = 1; j < (n); ++j)
      powers[i][j] = powers[i][j - 1] * 1LL * B % MOD[i];
  }
  fact[0] = 1;
  for (int i = 1; i < (1000001); ++i) fact[i] = fact[i - 1] * 1LL * i % MOD[0];
  for (int i = 0; i < (n); ++i) {
    int sz;
    scanf(" %d", &(sz));
    unordered_map<int, int> mp1;
    for (int j = 0; j < (sz); ++j) {
      int x;
      scanf(" %d", &(x));
      --x;
      ++mp1[x];
    }
    for (auto p : mp1) {
      for (int k = 0; k < (QTD); ++k) {
        val[k][p.first] =
            (val[k][p.first] + p.second * 1LL * powers[k][i]) % MOD[k];
      }
    }
  }
  unordered_map<long long, int> mp2;
  for (int j = 0; j < (m); ++j) {
    long long hash = val[0][j] * 1LL * MOD[1] + val[1][j];
    ++mp2[hash];
  }
  int ans = 1;
  for (auto p : mp2) {
    ans = ans * 1LL * fact[p.second] % MOD[0];
  }
  printf("%d\n", ans);
  return 0;
}
