#include <bits/stdc++.h>
using namespace std;
long long fact[1000001];
void f() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= 1000001; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(0);
  f();
  int n, m;
  cin >> n >> m;
  vector<vector<int> > p(m);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    for (int j = 0, var; j < t; j++) {
      cin >> var;
      p[var - 1].push_back(i);
    }
  }
  for (int i = 0; i < m; i++) sort(p[i].begin(), p[i].end());
  sort(p.begin(), p.end());
  int cnt = 1;
  long long ans = 1;
  for (int i = 1; i < m; i++) {
    if (p[i] == p[i - 1])
      cnt++;
    else
      ans = (ans * fact[cnt]) % 1000000007, cnt = 1;
  }
  ans = (ans * fact[cnt]) % 1000000007;
  cout << ans << "\n";
  return 0;
}
