#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e6 + 7;
const long long int mod = 1e9 + 7;
const long long int infi = LLONG_MAX;
long long int i, j, ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b,
                                        c, z, sum;
map<string, long long int> ms;
string s[M];
long long int fact[M], a[M];
int main() {
  scanf("%lld %lld", &n, &m);
  fact[0] = 1;
  for (i = 1; i < M; i++) fact[i] = (i * fact[i - 1]) % mod;
  for (j = 1; j < n + 1; j++) {
    long long int g;
    scanf("%lld", &g);
    map<long long int, long long int> cnt;
    for (i = 0; i < g; i++) {
      scanf("%lld", &a[i]);
      cnt[a[i]]++;
    }
    for (auto kk : cnt) {
      long long int count, type;
      type = kk.first;
      stack<char> temp;
      s[type].push_back('/');
      count = j;
      while (count > 0) {
        x = count % 10;
        count /= 10;
        temp.push(x + '0');
      }
      while (!temp.empty()) {
        s[type].push_back(temp.top());
        temp.pop();
      }
      s[type].push_back('-');
      count = kk.second;
      while (count > 0) {
        x = count % 10;
        count /= 10;
        temp.push(x + '0');
      }
      while (!temp.empty()) {
        s[type].push_back(temp.top());
        temp.pop();
      }
    }
  }
  for (i = 1; i < m + 1; i++) ms[s[i]]++;
  ans = 1;
  for (auto tt : ms) {
    ans = (ans * fact[tt.second]) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
