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