#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000005;
vector<int> vec[MAX_N];
long long fac[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i < MAX_N; i++) {
    fac[i] = fac[i - 1] * (long long)i % 1000000007;
  }
}
long long mul(long long x, long long y) { return x * y % 1000000007; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  make();
  for (int i = 0; i < (int)(n); ++i) {
    int q;
    cin >> q;
    for (int j = 0; j < (int)(q); ++j) {
      int a;
      cin >> a;
      vec[a - 1].push_back(i);
    }
  }
  map<vector<int>, int> mp;
  for (int i = 0; i < (int)(m); ++i) {
    mp[vec[i]]++;
  }
  long long ans = 1;
  for (auto&(it) : (mp)) {
    ans = mul(ans, fac[it.second]);
  }
  cout << ans << "\n";
  return 0;
}
