#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int MOD = 1e9 + 7;
int n, m;
vector<int> tmp;
vector<int> g[N];
int cnt1[N];
int marked[N];
int f[N];
int product(int a, int b) { return (1ll * a * b) % MOD; }
void mult(int &a, int b) { a = (1ll * a * b) % MOD; }
int main() {
  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = product(f[i - 1], i);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  int ans = 1;
  sort(g + 1, g + m + 1);
  int prev = 1;
  for (int i = 1; i <= m; i++) {
    if (i == m || g[i] != g[i + 1]) {
      mult(ans, f[i - prev + 1]);
      prev = i + 1;
    }
  }
  cout << ans;
  return 0;
}
