#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1000010 * 2;
int n, m;
vector<int> vec[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      vec[x].push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  sort(vec + 1, vec + m + 1);
  long long res = 1;
  long long cnt = 1;
  for (int i = 1; i < m; i++) {
    if (vec[i] == vec[i + 1])
      cnt++;
    else {
      while (cnt > 0) res = res * cnt % mod, cnt--;
      cnt = 1;
    }
  }
  while (cnt > 0) res = res * cnt % mod, cnt--;
  cout << res << endl;
}
