#include <bits/stdc++.h>
using namespace std;
const int p = 1000 * 1000 * 1000 + 7;
int main() {
  int n, m;
  vector<long long> fact(1000001);
  fact[0] = 1;
  for (int i = 1; i < 1000001; i++) fact[i] = (i * fact[i - 1]) % p;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int l;
      cin >> l;
      l--;
      v[l].first *= p;
      v[l].first += i + 1;
      v[l].second *= 2348621;
      v[l].second += i + 1;
    }
  }
  map<pair<int, int>, int> f;
  for (int i = 0; i < m; i++) f[v[i]]++;
  long long ans = 1;
  for (map<pair<int, int>, int>::iterator a = f.begin(); a != f.end(); a++)
    ans = (fact[(*a).second] * ans) % p;
  cout << ans;
}
