#include <bits/stdc++.h>
using namespace std;
long long int fact[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, i, j, x, g, ans, cursize;
  fact[0] = 1;
  for (i = 1; i < 1000005; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
  cin >> n >> m;
  vector<vector<long long int> > gym(m);
  for (i = 0; i < n; i++) {
    cin >> g;
    for (j = 1; j <= g; j++) {
      cin >> x;
      gym[x - 1].push_back(i);
    }
  }
  for (i = 0; i < m; i++) sort(gym[i].begin(), gym[i].end());
  sort(gym.begin(), gym.end());
  ans = 1;
  cursize = 1;
  for (i = 1; i < m; i++) {
    if (gym[i] == gym[i - 1])
      cursize++;
    else {
      ans = (ans * fact[cursize]) % 1000000007;
      cursize = 1;
    }
  }
  ans = (ans * fact[cursize]) % 1000000007;
  cout << ans << "\n";
  return 0;
}
