from collections import defaultdict MOD = 998244353 N,K = list(map(int,input().split())) people = [] for _ in range(K): l,s,*B = list(map(lambda x:int(x)-1,input().split())) people.append((s+1,B)) ans = 0 for i in range(30): use = set() for j in range(K): if(people[j][0]>>i & 1 == 0):continue use |= set(people[j][1]) ans += pow(2,i-1,MOD) * len(use) % MOD ans %= MOD print(ans)