#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
const long long md = 1000000007;
int n, m, k, x;
long long f[N];
long long kol, ans;
int main() {
  cin >> n >> m;
  vector<vector<int> > a(m + 1);
  f[0] = 1;
  f[1] = 1;
  ans = 1;
  for (int i = 1; i <= 1000000; ++i) {
    f[i] = (f[i - 1] * 1ll * i) % md;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> k;
    for (int j = 1; j <= k; ++j) {
      cin >> x;
      a[x].push_back(i);
    }
  }
  for (int j = 1; j <= m; ++j) {
    sort(a[j].begin(), a[j].end());
  }
  sort(a.begin(), a.end());
  for (int j = 1; j <= m; ++j) {
    if (a[j] == a[j - 1]) {
      kol++;
    } else {
      ans *= f[kol];
      ans %= md;
      kol = 1;
    }
  }
  ans *= f[kol];
  ans %= md;
  cout << ans;
}
