#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, MAXM = 1000006;
int P1[MAXN], P2[MAXN], MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
pair<int, int> hesh[MAXM];
int last[MAXM];
int fact[MAXM];
void add(int x, int y, int g) {
  int diff = g - last[x];
  last[x] = g;
  hesh[x].first = ((long long)hesh[x].first * P1[diff]) % MOD1;
  hesh[x].second = ((long long)hesh[x].second * P2[diff]) % MOD2;
  hesh[x].first = ((long long)hesh[x].first + y) % MOD1;
  hesh[x].second = ((long long)hesh[x].second + y) % MOD2;
}
int n, m;
int main() {
  P1[0] = 1;
  P2[0] = 1;
  P1[1] = 5779, P2[1] = 3511;
  for (int i = 2; i < MAXN; ++i) {
    P1[i] = ((long long)P1[i - 1] * P1[1]) % MOD1;
    P2[i] = ((long long)P2[i - 1] * P2[1]) % MOD2;
  }
  fact[0] = 1;
  for (int i = 1; i < MAXM; ++i) {
    fact[i] = ((long long)fact[i - 1] * i) % MOD1;
  }
  scanf("%d%d", &n, &m);
  int x, g;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &g);
    map<int, int> types;
    for (int j = 0; j < g; ++j) {
      scanf("%d", &x);
      x--;
      types[x]++;
    }
    for (auto j : types) {
      add(j.first, j.second, i);
    }
  }
  for (int i = 0; i < m; ++i) {
    int diff = n - last[i];
    hesh[i].first = ((long long)hesh[i].first * P1[diff]) % MOD1;
    hesh[i].second = ((long long)hesh[i].second * P2[diff]) % MOD2;
  }
  sort(hesh, hesh + m);
  int prev = -1, sol = 1;
  for (int i = 0; i < m - 1; ++i) {
    if (hesh[i] != hesh[i + 1]) {
      sol = ((long long)sol * fact[i - prev]) % MOD1;
      prev = i;
    }
  }
  sol = ((long long)sol * fact[m - prev - 1]) % MOD1;
  printf("%d\n", sol);
  return 0;
}
