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