#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005, P = 1000000007, Mod1 = 233, Mod2 = 109;
int n, m, ans, fac[MAXN];
long long Hash[MAXN];
map<long long, int> vis;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = fac[0] = 1; i <= m; ++i) fac[i] = 1LL * i * fac[i - 1] % P;
  long long Pow = 1;
  for (int i = 1; i <= n; ++i) {
    int num;
    Pow *= P;
    scanf("%d", &num);
    for (int x, j = 1; j <= num; ++j) {
      scanf("%d", &x);
      Hash[x] += Pow;
    }
  }
  ans = 1;
  for (int i = 1; i <= m; ++i) ++vis[Hash[i]];
  for (map<long long, int>::iterator it = vis.begin(); it != vis.end(); ++it)
    ans = 1LL * ans * fac[it->second] % P;
  printf("%d\n", ans);
  return 0;
}
