#include <bits/stdc++.h>
using namespace std;
long long n, m, fact[1000005], ans = 1, key;
vector<long long> arr[1000005];
inline void precalc() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
  }
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; ++i) {
    long long t = 0;
    scanf("%lld", &t);
    for (int j = 1; j <= t; ++j) {
      long long a = 0;
      scanf("%lld", &a);
      arr[a].push_back(i);
    }
  }
  precalc();
  sort(arr + 1, arr + m + 1);
  for (int i = 1; i <= m; ++i) {
    if (arr[i] == arr[i - 1]) {
      ++key, ans = (ans * key) % 1000000007;
    } else
      key = 1;
  }
  printf("%lld", ans);
  return 0;
}
