#include <bits/stdc++.h>
using namespace std;
int dp[1000004];
int mul(int N, int M) {
  if (M == 0) {
    return 0;
  }
  if (M == 1) {
    return N;
  }
  return ((mul(N, M / 2) * 2) % 1000000007 + (M & 1 ? N : 0)) % 1000000007;
}
int fact() {
  dp[1] = 1;
  for (int i = 2; i <= 1000000; ++i) {
    dp[i] = mul(dp[i - 1], i) % 1000000007;
  }
  return 0;
}
int areEqual(vector<int> v1, vector<int> v2) {
  if (v1.size() == v2.size()) {
    for (int i = 0; i < v1.size(); ++i) {
      if (v1[i] != v2[i]) return 0;
    }
    return 1;
  }
  return 0;
}
int main() {
  fact();
  int N, M;
  scanf("%d %d", &N, &M);
  vector<vector<int> > vv;
  vector<int> v;
  for (int i = 0; i <= M; ++i) {
    vv.push_back(v);
  }
  for (int i = 1; i <= N; ++i) {
    int G;
    scanf("%d", &G);
    for (int j = 0; j < G; ++j) {
      int x;
      scanf("%d", &x);
      vv[x].push_back(i);
    }
  }
  sort(vv.begin(), vv.end());
  int cnt = 1, ans = 1;
  for (int i = 2; i <= M; ++i) {
    if (areEqual(vv[i - 1], vv[i])) {
      ++cnt;
    } else {
      ans = mul(ans, dp[cnt]);
      cnt = 1;
    }
  }
  ans = mul(ans, dp[cnt]);
  printf("%d\n", ans);
  return 0;
}
