#include <bits/stdc++.h>
using namespace std;
constexpr int64_t P0 = 2000003;
constexpr int64_t P1 = 2000017;
constexpr int64_t M0 = 3000000000013;
constexpr int64_t M1 = 2000000000003;
class TaskC {
 public:
  struct Class {
    int id;
    int cnt;
  };
  struct Hash {
    int64_t a, b;
    Hash() : a(0), b(0) {}
    void update(int addition) {
      a = (a * P0 + addition) % M0;
      b = (b * P1 + addition) % M1;
    }
    bool operator<(const Hash& other) const {
      return std::tie(a, b) < std::tie(other.a, other.b);
    }
  };
  void solve(std::istream& in, std::ostream& out) {
    int n, m;
    in >> n >> m;
    vector<vector<int>> schools(n);
    vector<Class> classes;
    int timer = 0;
    vector<Hash> hashes(m);
    for (int i = 0; i < n; i++) {
      int k;
      in >> k;
      auto& school = schools[i];
      for (int j = 0; j < k; j++) {
        int id;
        in >> id;
        --id;
        school.push_back(id);
      }
      sort(school.begin(), school.end());
      classes.clear();
      int l = 0;
      while (l < k) {
        int id = school[l], cnt = 0;
        while (l < k && school[l] == id) {
          ++l;
          ++cnt;
        }
        classes.push_back(Class{id, cnt});
      }
      sort(classes.begin(), classes.end(),
           [](Class lhs, Class rhs) { return lhs.cnt < rhs.cnt; });
      l = 0;
      while (l < classes.size()) {
        ++timer;
        int cnt = classes[l].cnt;
        while (l < classes.size() && classes[l].cnt == cnt) {
          int id = classes[l].id;
          ++l;
          hashes[id].update(timer);
        }
      }
    }
    map<Hash, int> was;
    int64_t result = 1;
    int64_t MOD = (1000000000 + 7);
    for (auto hash : hashes) {
      ++was[hash];
      result = (result * was[hash]) % MOD;
    }
    out << result << "\n";
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  TaskC solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  in.tie(0);
  out << std::fixed;
  out.precision(20);
  solver.solve(in, out);
  return 0;
}
