#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a[1000006];
int md = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int u;
    cin >> u;
    for (int j = 1; j <= u; j++) {
      int v;
      cin >> v;
      a[v].push_back(i);
    }
  }
  sort(a + 1, a + m + 1);
  int t = 1;
  int ans = 1;
  for (int i = 2; i <= m; i++) {
    if (a[i] == a[i - 1]) {
      t++;
      ans = (long long)ans * t % md;
    } else
      t = 1;
  }
  cout << ans;
}
