#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<multiset<int> > a(m, multiset<int>());
  for (int i = 0; i < n; i++) {
    int gi;
    cin >> gi;
    for (int j = 0; j < gi; j++) {
      int gj;
      cin >> gj;
      a[gj - 1].insert(i);
    }
  }
  sort(a.begin(), a.end());
  long long ans = 1;
  long long t = 1;
  for (int i = 1; i < a.size(); i++) {
    (a[i] == a[i - 1]) ? t++ : t = 1;
    ans *= t;
    ans %= 1000000007;
  }
  cout << ans;
  return 0;
}
