N, M = map(int, input().split(' '))
k = []
s = []
for i in range(M):
    ksi = list(map(int, input().split(' ')))
    ki = ksi.pop(0)
    si = ksi
    k.append(ki)
    s.append(si)
p = list(map(int, input().split(' ')))

cnt = 0
for i in range(M):
    flag = True
    for j in range(i+1, M):
        if s[i] == s[j]:
            flag = False
            break
    if flag is True:
        cnt += 1
num = (int)(2**(N-cnt))
print(num)