class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x n,m = map(int,input().split()) uf = UnionFind(n) for i in range(m): l = list(map(int,input().split())) v = [0] * n for j in range(1, l[0]+1): v[l[j] - 1] = 1 a = -1 b = -1 for j in range(n): if v[j] == 1: if a >= 0: uf.union(a, j) a = j else: if b >= 0: uf.union(b, j) b = j mod = 998244353 ans = pow(2, n+1, mod) inv2 = pow(2, mod-2, mod) for i in range(n): if uf.parents[i] < 0: ans *= inv2 ans %= mod print(ans)