#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int MOD = 1e9 + 7;
int n, m;
vector<int> tmp;
vector<int> g[N];
int cnt1[N];
int marked[N];
int f[N];
map<vector<int>, int> cnt;
int product(int a, int b) { return (1ll * a * b) % MOD; }
void mult(int &a, int b) { a = (1ll * a * b) % MOD; }
int main() {
  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = product(f[i - 1], i);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) cnt[g[i]]++;
  int ans = 1;
  for (auto p : cnt) {
    mult(ans, f[p.second]);
  }
  cout << ans;
  return 0;
}
