#include <bits/stdc++.h>
using namespace std;
int x, k, n, m;
vector<int> v[1000005];
long long ans = 1, fac[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  fac[0] = 1;
  for (long long i = 1; i <= 1000005 - 5; i++)
    fac[i] = (fac[i - 1] * i) % 1000000007;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    for (int j = 1; j <= k; j++) {
      cin >> x;
      v[x].push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) sort(v[i].begin(), v[i].end());
  sort(v + 1, v + 1 + m);
  for (int i = 1; i <= m; i++) {
    int start = i;
    while (i + 1 <= m && v[i] == v[i + 1]) i++;
    ans *= fac[i - start + 1];
    ans %= 1000000007;
  }
  cout << ans;
}
