#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 1e6 + 10;
const int M = 1e4 + 10;
const long long mod = 1000000007;
const double eps = 1e-10;
const double pi = acos(-1.0);
int n, m;
long long cnt[N];
vector<int> ve;
long long k[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long p = 1;
  for (int i = 1; i <= n; i++) {
    int g;
    cin >> g;
    ve.clear();
    for (int j = 0; j < g; j++) {
      int t;
      cin >> t;
      ve.push_back(t);
    }
    sort(ve.begin(), ve.end());
    for (int j = 0, k; j < g; j = k) {
      k = j + 1;
      while (k < g && ve[j] == ve[k]) k++;
      cnt[ve[j]] += (k - j) * p;
    }
    p = p * 1000007 % 1000000000009ll;
  }
  sort(cnt + 1, cnt + 1 + m);
  k[0] = 1;
  for (int i = 1; i < N; i++) k[i] = k[i - 1] * i % mod;
  long long ans = 1;
  for (int i = 1, j; i <= m; i = j) {
    j = i + 1;
    while (j <= m && cnt[i] == cnt[j]) j++;
    ans = ans * k[j - i] % mod;
  }
  cout << ans << endl;
  return 0;
}
