#include <bits/stdc++.h>
using namespace std;
inline string toString(long long x) {
  string ans = "";
  while (x) ans.push_back(x % 10 + '0'), x /= 10;
  if (ans.size() == 0) ans = "0";
  for (long long i = 0; i < ans.size() / 2; i++)
    swap(ans[i], ans[ans.size() - 1 - i]);
  return ans;
}
inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
const long long mod = 1e9 + 7;
inline signed rd() {
  signed ans = 0;
  char last = ' ', ch = getchar();
  while (!(ch >= '0' && ch <= '9')) last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9')
    ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar();
  return ans;
}
inline long long QPow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
inline long long QPow(long long a, long long b, const long long &mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long d = a;
  if (b == 0)
    x = 1, y = 0;
  else {
    d = exgcd(b, a % b, y, x), y -= a / b * x;
  }
  return d;
}
const long double PI = 3.141592653589793115997963468544185161590576171875;
const long long maxn = 1000005;
long long fac[maxn];
void init() {
  fac[0] = 1;
  for (long long i = 1; i < maxn; i++) fac[i] = i * fac[i - 1] % mod;
}
vector<signed> pos[maxn];
unordered_map<string, long long> cnt;
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m, x, y, d;
  init();
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    for (long long j = 1; j <= x; j++) cin >> y, pos[y].push_back(i);
  }
  for (long long i = 1; i <= m; i++) {
    string tmp = "-";
    for (long long j = 0; j < pos[i].size(); j++) {
      string num = toString(pos[i][j]);
      for (long long k = 0; k < num.size(); k++) tmp.push_back(num[k]);
      tmp.push_back('-');
    }
    cnt[tmp]++;
  }
  long long ans = 1;
  for (auto it : cnt) ans = ans * fac[it.second] % mod;
  cout << ans << endl;
  return 0;
}
