#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const double eps = 1e-9;
int n;
struct cmp {
  bool operator()(int const& lhs, int const& rhs) const { return lhs > rhs; }
};
void solveAA() {
  int t;
  cin >> t;
  for (int z = 0; z < t; z++) {
    cin >> n;
    set<int, cmp> p;
    map<int, int> mp;
    map<int, int> rev;
    for (int i = 0; i < n; i++) {
      int tem;
      cin >> tem;
      p.insert(tem);
      mp[tem] = i + 1;
      rev[i + 1] = tem;
    }
    map<int, vector<int> > gr;
    map<int, set<int, cmp> > grr;
    for (int i = 0; i < n; i++) {
    }
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      int aa = rev[a];
      int bb = rev[b];
      grr[a].erase(aa);
      grr[a].erase(bb);
      grr[b].erase(aa);
      grr[b].erase(bb);
      gr[a].push_back(b);
      gr[b].push_back(a);
    }
    vector<int> ans(n, 0);
    for (int i = 0; i < n; i++) {
      int temp = i + 1;
      set<int, cmp> te_ve = grr[temp];
      if (!te_ve.empty()) {
        ans[temp - 1] = mp[*te_ve.begin()];
      } else
        ans[temp - 1] = 0;
    }
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
}
void solveA() {}
long long _sieve_size;
bitset<10000010> bs;
vector<int> minp;
void sieve(long long upperbound) {
  _sieve_size = upperbound + 1;
  bs.set();
  vector<int> primes(_sieve_size, 0);
  bs[0] = bs[1] = 0;
  for (int i = 2; i <= _sieve_size; i += 2) primes[i] = 2;
  for (long long i = 3; i <= _sieve_size; i += 2) {
    if (bs[i]) {
      primes[i] = i;
      for (long long j = i; (j * i) < _sieve_size; j += 2) {
        if (bs[j * i]) bs[j * i] = 0, primes[j * i] = i;
      }
    }
  }
  primes[1] = 1;
  minp.push_back(0);
  minp.push_back(1);
  for (long long i = 2; i <= _sieve_size; i++) {
    minp.push_back(primes[i]);
  }
}
vector<int> primefactors(long long N) {
  vector<int> factors;
  long long a = minp[N];
  factors.push_back(a);
  while (N % a == 0 && N != 1) {
    N = N / a;
  }
  if (N == 1) {
    return factors;
  }
  int y = 0;
  vector<int> f = primefactors(N);
  for (long long i = 0; i < f.size(); i++) {
    factors.push_back(f[i]);
  }
  return factors;
}
void solveB() {}
long long mod = 1000000007;
vector<int> per(1000002);
void solveC() {
  int t = 1;
  per[t] = t;
  for (int i = 2; i < 1000002; i++) {
    t = ((t % mod) * (i % mod)) % mod;
    per[i] = t;
  }
  int m;
  cin >> n >> m;
  vector<vector<int> > v(m);
  for (int i = 0; i < n; i++) {
    vector<int> temp;
    int siz;
    cin >> siz;
    for (int j = 0; j < siz; j++) {
      int y;
      cin >> y;
      v[y - 1].push_back(i + 1);
    }
  }
  map<vector<int>, int> yo;
  long long ans = 1;
  for (int i = 0; i < m; i++) {
    yo[v[i]]++;
    ans = ((ans % mod) * (yo[v[i]] % mod)) % mod;
  }
  cout << ans << endl;
}
void solveCC() {
  int e;
  cin >> n >> e;
  map<int, int> mp;
  vector<vector<int> > v(e, vector<int>(2, 0));
  for (int i = 0; i < e; i++) {
    int a, b;
    cin >> a >> b;
    v[i][0] = a;
    v[i][1] = b;
    mp[a]--;
    mp[b]++;
  }
  map<int, int> vis;
  for (int i = 0; i < e; i++) {
    int a = v[i][0];
    int b = v[i][1];
    if (mp[a] < 0 && mp[b] != 0) {
      mp[a] += 2;
      mp[b] -= 2;
      swap(v[i][0], v[i][1]);
    } else if (mp[b] > 0 && mp[a] != 0) {
      mp[a] += 2;
      mp[b] -= 2;
      swap(v[i][0], v[i][1]);
    }
  }
  vector<vector<int> > grp(n);
  for (int i = 0; i < e; i++) {
    int a = v[i][0];
    int b = v[i][1];
    grp[a - 1].push_back(b);
  }
  stack<int> st;
  st.push(1);
  while (!st.empty()) {
    int t = st.top();
    st.pop();
    vis[t] = 1;
    vector<int> ty = grp[t - 1];
    for (int i = 0; i < ty.size(); i++) {
      int r = ty[i];
      if (vis[r] == 0) {
        st.push(r);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (mp[i + 1] != 0 || vis[i + 1] == 0) {
      cout << "NO";
      return;
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < e; i++) {
    cout << v[i][0] << " " << v[i][1] << endl;
  }
}
void solveD() {}
bool isprime(int n) {
  if (n <= 1) return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
long long yo = 1000000007;
map<pair<int, int>, long long> po;
long long fun(int r, int n) {
  if (po[make_pair(r, n)] != 0) {
    return po[make_pair(r, n)];
  }
  if (isprime(n)) {
    return r + 2;
  }
  map<int, int> m;
  int t = 0;
  vector<int> v = primefactors(n);
  if (n == 1) {
    return 1;
  }
  if (r == 0) {
    long long num = 1;
    if (n == 1) {
    } else {
      num = t * (t - 1);
      num += 2;
    }
    po[make_pair(r, n)] = num;
    return num;
  }
  long long num = 0;
  for (int i = 1; i < sqrt(n); i++) {
    int a = i;
    if (n % a == 0) {
      long long cur = ((fun(r - 1, a) % yo) + (fun(r - 1, n / a) % yo) % yo);
      num = ((num % yo) + (cur % yo)) % yo;
    }
  }
  int a = sqrt(n);
  if (a * a == n && a != 1) {
    long long cur = ((fun(r - 1, a) % yo) + (fun(r - 1, n / a) % yo) % yo) / 2;
    num = ((num % yo) + (cur % yo)) % yo;
  }
  po[make_pair(r, n)] = num;
  return num;
}
void solveE() {
  sieve(1000000);
  int q;
  cin >> q;
  for (int l = 0; l < q; l++) {
    int r;
    cin >> r >> n;
    cout << fun(r, n) << endl;
  }
}
void solveD2() {}
void solveE2() {}
int main() {
  solveC();
  return 0;
}
