#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int oo = 1000000007;
int n, m;
vector<int> poke[100005];
vector<pair<int, int> > vec[100005];
long long perm[N];
vector<pair<int, int> > a[N];
map<vector<pair<int, int> >, int> Map;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (n); ++i) {
    int t;
    scanf("%d", &t);
    for (int j = 1; j <= (t); ++j) {
      int x;
      scanf("%d", &x);
      poke[i].push_back(x);
    }
    sort(poke[i].begin(), poke[i].end());
  }
  for (int i = 1; i <= (n); ++i) {
    vec[i].push_back(make_pair(1, poke[i][0]));
    for (int j = 1; j < poke[i].size(); ++j)
      if (poke[i][j] == poke[i][j - 1])
        vec[i].back().first++;
      else {
        vec[i].push_back(make_pair(1, poke[i][j]));
      }
  }
  for (int i = 1; i <= (n); ++i)
    for (int j = 0; j < (vec[i].size()); ++j) {
      a[vec[i][j].second].push_back(make_pair(i, vec[i][j].first));
    }
  for (int i = 1; i <= (m); ++i) Map[a[i]]++;
  perm[1] = 1;
  for (int i = 2; i <= m; ++i) perm[i] = (perm[i - 1] * i) % oo;
  long long ans = 1;
  for (__typeof(Map.begin()) it = Map.begin(); it != Map.end(); ++it) {
    ans = (ans * perm[it->second]) % oo;
  }
  cout << ans;
}
