#include #include #include #include using namespace std; const int MOD = 998244353; struct union_find { int n; std::vector par; std::vector sz; int num_of_components; union_find(int n) : n(n) { par.resize(n); sz.resize(n); for (int i = 0; i < n; i++) { par[i] = i; sz[i] = 1; } num_of_components = n; } int find(int i) { assert(0 <= i && i < n); return (i == par[i]) ? i : par[i] = find(par[i]); } bool same(int i, int j) { assert(0 <= i && i < n); assert(0 <= j && j < n); return find(i) == find(j); } void unite(int i, int j) { assert(0 <= i && i < n); assert(0 <= j && j < n); i = find(i), j = find(j); if (i == j) { return; } if (sz[i] < sz[j]) { std::swap(i, j); } par[j] = i; sz[i] += sz[j]; num_of_components--; } int size() { return n; } int size(int i) { assert(0 <= i && i < n); return sz[find(i)]; } int count() { return num_of_components; } bool is_root(int i) { assert(0 <= i && i < n); return i == find(i); } int operator[](int i) { return find(i); } }; int main() { int n, m; cin >> n >> m; bitset<1005> b[1005]; for(int i = 0; i < m; i++) { int l; cin >> l; for(int j = 0; j < l; j++) { int a; cin >> a; a--; b[a].set(i); } } union_find uf(n); for(int u = 0; u < n; u++) { for(int v = u + 1; v < n; v++) { if(b[u] == b[v]) { uf.unite(u, v); } } } int ans = 1; for(int i = 0; i < uf.count(); i++) { ans = ans * 2 % MOD; } cout << ans << endl; }