#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<int> vec[1000005];
int val[500005], cnt = 1;
map<int, int> ch[500005];
long long J[1000005];
int main(int argc, const char *argv[]) {
  cin.sync_with_stdio(false);
  J[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    J[i] = i * J[i - 1] % mod;
  }
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int g;
    cin >> g;
    for (int j = 0; j < g; j++) {
      int t;
      cin >> t;
      vec[t].push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) {
    int now = 0;
    for (auto x : vec[i]) {
      if (!ch[now][x]) {
        ch[now][x] = cnt++;
      }
      now = ch[now][x];
    }
    val[now]++;
  }
  long long ans = 1;
  for (int i = 0; i < cnt; i++) {
    ans = ans * J[val[i]] % mod;
  }
  cout << ans << endl;
  return 0;
}
