#include <bits/stdc++.h>
using namespace std;
const int maxm = 1000005;
vector<int> vec[maxm];
int n, m, t, c;
long long res, tc;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    while (t--) {
      scanf("%d", &c);
      vec[c].push_back(i);
    }
  }
  sort(vec + 1, vec + m + 1);
  res = 1;
  for (int i = 1; i <= m; ++i)
    if (vec[i] == vec[i - 1]) {
      ++tc;
      res = (res * tc) % 1000000007;
    } else
      tc = 1;
  printf("%lld\n", res);
  return 0;
}
