#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxm = 1000000;
vector<int> vt[maxm + 2];
const int mod = 1e9 + 7;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int g;
    cin >> g;
    while (g--) {
      int x;
      cin >> x;
      vt[x].push_back(i);
    }
  }
  sort(vt + 1, vt + m + 1);
  long long ans = 1LL, cnt = 1LL;
  for (int i = 2; i <= m; i++) {
    if (vt[i] == vt[i - 1]) {
      cnt++;
      ans = (ans * cnt) % mod;
    } else {
      cnt = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
