#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 0x7FFFFFFFFFFFFFFF / 2;
vector<int> arr[1000001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, g, a;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> g;
    while (g--) {
      cin >> a;
      arr[a].push_back(i);
    }
  }
  sort(arr + 1, arr + m + 1);
  long long z = 1;
  long long ans = 1;
  for (int i = 2; i <= m; i++) {
    if (arr[i] == arr[i - 1]) {
      z++;
      ans = (ans * z) % mod;
    } else {
      z = 1;
    }
  }
  cout << ans;
  return 0;
}
