#include <bits/stdc++.h>
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
using namespace std;
const long long mod = 1e9 + 7;
int n, m;
long long fact(int k) {
  if (k == 0LL) {
    return 1LL;
  } else {
    return (k * fact(k - 1)) % mod;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  vector<string> spec(m);
  for (long long i = (long long)1; i < (long long)n + 1; i++) {
    int g;
    cin >> g;
    map<int, int> poke_cnts;
    for (long long _ = (long long)0; _ < (long long)g; _++) {
      int p;
      cin >> p;
      poke_cnts[p]++;
    }
    for (auto& p : poke_cnts) {
      spec[p.first - 1] += "p" + to_string(i) + "i" + to_string(p.second);
    }
  }
  map<string, int> pos;
  for (auto& s : spec) {
    pos[s]++;
  }
  long long res = 1;
  for (auto& p : pos) {
    res = (res * fact(p.second)) % mod;
  }
  cout << res << "\n";
  return 0;
}
