import sys input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd mod = 998244353 n,m = map(int,input().split()) s = set() a = [] l = [] for i in range(m): aa = list(map(int,input().split())) l.append(aa[0]) a.append(set(aa[1:])) p = [-1]*(m+1) def find(x): if p[x] < 0: return x else: p[x] = find(p[x]) return p[x] def union(x,y): x = find(x) y = find(y) if x == y: return if p[x] > p[y]: x,y = y,x p[x] += p[y] p[y] = x un = [] for i in range(1,n+1): rep = -1 flg = 0 for j in range(m): if i in a[j] and rep == -1: rep = j flg = 1 else: union(j,rep) if flg == 0: un.append(i) d = defaultdict(int) for i in range(1,m+1): d[find(i)] += 1 ans = pow(2, (un != [])) for v in d.values(): ans *= pow(2, v+1, mod) ans %= mod print(ans)