#include <bits/stdc++.h>
using namespace std;
const int N = int(1e6) + 10, mod = int(1e9) + 7;
vector<int> g[N];
int n, m;
long long first[N + 10], ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, k, x; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  first[0] = 1;
  for (int i = 1; i < N; i++) {
    first[i] = first[i - 1] * i % mod;
  }
  ans = 1;
  sort(g + 1, g + m + 1);
  int cur = 1;
  for (int i = 2; i <= m; i++) {
    if (g[i] == g[i - 1])
      cur++;
    else {
      ans = ans * first[cur] % mod;
      cur = 1;
    }
  }
  ans = ans * first[cur] % mod;
  printf("%d", int(ans));
  return 0;
}
