#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
vector<int> v[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    for (int j = 1; j <= x; j++) {
      int y;
      scanf("%d", &y);
      v[y].push_back(i);
    }
  }
  sort(v + 1, v + m + 1);
  int ans = 1;
  int cnt = 1;
  for (int i = 2; i <= m; i++) {
    if (v[i] == v[i - 1]) {
      cnt++;
      ans = (long long)ans * cnt % 1000000007;
    } else {
      cnt = 1;
    }
  }
  printf("%d", ans);
  return 0;
}
