#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
vector<int> s[maxn];
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int num;
    cin >> num;
    for (int j = 0; j < num; j++) {
      int b;
      cin >> b;
      s[b].push_back(i);
    }
  }
  sort(s + 1, s + m + 1);
  long long ans = 1;
  int tmp = 1;
  for (int i = 2; i <= m; i++) {
    if (s[i] == s[i - 1]) {
      tmp++;
      ans = (ans * tmp) % mod;
    } else
      tmp = 1;
  }
  cout << ans << endl;
}
