#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
vector<int> a[1000001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int g;
    scanf(" %d", &g);
    while (g--) {
      int p;
      scanf(" %d", &p);
      a[p].push_back(i);
    }
  }
  sort(a, a + m + 1);
  int t = 1, ans = 1;
  for (int i = 2; i <= m; ++i) {
    if (a[i] == a[i - 1])
      ans = (long long)ans * ++t % mod;
    else
      t = 1;
  }
  cout << ans;
  return 0;
}
