#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
vector<int> d[SIZE];
int a[SIZE];
bool cmp(int x, int y) { return d[x] < d[y]; }
int main() {
  int m, n;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < (m); ++i) {
    int(K);
    scanf("%d", &K);
    for (int j = 0; j < (K); ++j) {
      int(x);
      scanf("%d", &x);
      d[x - 1].push_back(i);
    }
  }
  for (int i = 0; i < (n); ++i) a[i] = i;
  sort(a, a + n, cmp);
  int an = 1;
  for (int i = 0, j; i < n; i = j) {
    for (j = i + 1; j < n && d[a[j]] == d[a[i]]; j++)
      an = an * (long long)(j + 1 - i) % MOD;
  }
  return 0 * printf("%d\n", an);
}
