#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 100001;
const int M = 1000001;
vector<int> v[M];
map<vector<int>, int> MP;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int g;
    scanf("%d", &g);
    while (g--) {
      int x;
      scanf("%d", &x);
      v[x].push_back(i);
    }
  }
  long long int ans = 1;
  int cnt = 0;
  for (int i = 1; i < m + 1; i++) {
    if (!v[i].size()) {
      cnt++;
      ans *= cnt;
      ans %= mod;
      continue;
    }
    MP[v[i]]++;
    ans *= MP[v[i]];
    ans %= mod;
  }
  printf("%d\n", (int)ans);
  return 0;
}
