#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long mod = 1e9 + 7;
long long n, m, k, x;
long long a[N], b[N];
vector<long long> v[N];
int main() {
  ios_base::sync_with_stdio(0);
  int T = 1;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> k;
      while (k--) {
        cin >> x;
        v[x].push_back(i);
      }
    }
    sort(v + 1, v + m + 1);
    long long sum = 1;
    long long fac = 1;
    long long ans = 1;
    for (int i = 2; i <= m; i++) {
      if (v[i] == v[i - 1]) {
        sum++;
        fac = (fac * sum) % mod;
      } else {
        ans = (ans * fac) % mod;
        fac = sum = 1;
      }
    }
    ans = (ans * fac) % mod;
    cout << ans;
  }
  return 0;
}
