#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 1e6 + 6;
int n, m, k, x, res = 1, fact[maxn];
map<vector<int>, int> f;
vector<int> a[maxn];
int main() {
  fact[0] = 1;
  for (int i = 1; i < maxn; ++i) fact[i] = 1LL * fact[i - 1] * i % mod;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &k);
    for (int j = 1; j <= k; ++j) {
      scanf("%d", &x);
      a[x].push_back(i);
    }
  }
  for (int i = 1; i <= m; ++i) sort(a[i].begin(), a[i].end()), ++f[a[i]];
  for (map<vector<int>, int>::iterator it = f.begin(); it != f.end(); ++it) {
    res = 1LL * res * fact[it->second] % mod;
  }
  printf("%d", res);
}
