#include <bits/stdc++.h>
using namespace std;
signed main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> h1(m, 1);
  vector<unsigned long long> h2(m, 1);
  vector<int64_t> last(m, -1);
  int64_t mod1 = 1000000007;
  int64_t mod2 = 1000000009;
  vector<int64_t> pow1(100001);
  pow1[0] = 1;
  vector<unsigned long long> pow2(100001);
  pow2[0] = 1;
  for (int64_t i = 1; i < 100001; i++) {
    pow1[i] = pow1[i - 1] * 1000000007;
    pow2[i] = pow2[i - 1] * 1000000009;
  }
  vector<int64_t> fact(1000001);
  fact[0] = 1;
  for (int64_t i = 1; i <= 1000000; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= 1000000007;
  }
  for (int64_t i = 0; i < n; i++) {
    int64_t gi;
    cin >> gi;
    map<int64_t, int64_t> cou;
    for (int64_t j = 0; j < gi; j++) {
      int64_t tmp;
      cin >> tmp;
      cou[tmp - 1]++;
    }
    for (auto k = cou.begin(); k != cou.end(); k++) {
      h1[k->first] = h1[k->first] * pow1[i - last[k->first]] + (k->second);
      h2[k->first] = h2[k->first] * pow2[i - last[k->first]] + (k->second);
      last[k->first] = i;
    }
  }
  for (int64_t i = 0; i < m; i++) {
    h1[i] *= pow1[n - 1 - last[i]];
    h2[i] *= pow2[n - 1 - last[i]];
  }
  map<pair<int64_t, unsigned long long>, int64_t> cl;
  for (int64_t i = 0; i < m; ++i) {
    cl[make_pair(h1[i], h2[i])]++;
  }
  int64_t ans = 1;
  for (auto i = cl.begin(); i != cl.end(); i++) {
    ans *= fact[i->second];
    ans %= 1000000007;
  }
  cout << ans;
}
