#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
vector<vector<int> > g(1000002);
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (int)(n); ++i) {
    scanf("%d", &x);
    while (x--) {
      scanf("%d", &y);
      g[y].push_back(i);
    }
  }
  sort(g.begin() + 1, g.begin() + 1 + m);
  long long ans = 1, rep = 1;
  for (int i = (2); i <= (int)(m); ++i)
    if (g[i] == g[i - 1])
      ++rep, ans *= rep, ans %= 1000000007;
    else
      rep = 1;
  cout << ans;
}
