#include <bits/stdc++.h>
using namespace std;
vector<int> c[1000005];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int j = 1; j <= n; ++j) {
    int g;
    cin >> g;
    for (int i = 1; i <= g; ++i) {
      int v;
      cin >> v;
      c[v].push_back(j);
    }
  }
  sort(c + 1, c + 1 + m);
  long long t = 1;
  long long ans = 1;
  for (int i = 2; i <= m; ++i) {
    if (c[i] == c[i - 1])
      ans = (ans * (++t)) % 1000000007;
    else
      t = 1;
  }
  cout << ans << endl;
  return 0;
}
