#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
long long fac[1000005];
void factorial(int mx) {
  fac[0] = 1ll;
  for (int i = 1; i <= mx; i++) {
    fac[i] = fac[i - 1] * (long long)i;
    fac[i] %= 1000000007;
  }
}
int main() {
  factorial(1000005 - 5);
  int n, m, vol, type;
  long long ans, cnt = 1ll;
  scanf("%d", &n);
  scanf("%d", &m);
  vector<vector<int> > vec(m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &vol);
    while (vol--) {
      scanf("%d", &type);
      vec[type - 1].push_back(i);
    }
  }
  for (int i = 0; i < m; i++) sort(vec[i].begin(), vec[i].end());
  sort(vec.begin(), vec.end());
  ans = 1ll;
  for (int i = 1; i <= m - 1; i++) {
    if (vec[i] == vec[i - 1])
      ans *= ++cnt;
    else
      cnt = 1;
    ans %= 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
