#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 300;
const int mod = 1000000007;
map<int, int> mp[N];
int cnt[N];
int szt = 1;
void addChar(int &state, int ch) {
  if (!mp[state].count(ch)) {
    mp[state][ch] = szt;
    state = szt;
    szt++;
  } else {
    int nstate = mp[state][ch];
    state = nstate;
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int> > g(m);
  for (int i = 0; i < n; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 0; j < cnt; j++) {
      int pok;
      scanf("%d", &pok);
      pok--;
      g[pok].push_back(i);
    }
  }
  int ans = 1;
  for (int i = 0; i < m; i++) {
    int curst = 0;
    for (int j = 0; j < g[i].size(); j++) addChar(curst, g[i][j]);
    cnt[curst]++;
    ans = (ans * 1ll * cnt[curst]) % mod;
  }
  cout << ans << endl;
}
