#include <bits/stdc++.h>
using namespace std;
long long int fact[1000005];
int main() {
  int n, m, i, j, k, l;
  cin >> n >> m;
  vector<int> v[m + 2];
  fact[0] = 1;
  fact[1] = 1;
  for (i = 2; i < 1000005; i++) {
    long long int jl = i;
    fact[i] = (fact[i - 1] * jl) % 1000000007;
  }
  unordered_map<string, int> ma;
  for (i = 1; i <= n; i++) {
    cin >> j;
    while (j--) {
      cin >> k;
      v[k].push_back(i);
    }
  }
  sort(v + 1, v + m + 1);
  long long int ans = 1;
  long long int dl = 1;
  for (i = 2; i <= m; i++) {
    if (v[i] == v[i - 1]) {
      dl++;
      ans = (ans * dl) % 1000000007;
    } else {
      dl = 1;
    }
  }
  cout << ans;
  return 0;
}
