#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MM = 1e6;
vector<int> loai[MM + 2];
map<vector<int>, int> mp;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); i++) {
    int t, k;
    scanf("%d", &t);
    while (t--) {
      scanf("%d", &k);
      loai[k - 1].push_back(i);
    }
  }
  long long ans = 1;
  for (int i = 0; i < (m); i++) {
    mp[loai[i]] += 1;
    ans *= mp[loai[i]];
    ans %= mod;
  }
  cout << ans;
  return 0;
}
