import math

n, m = (int(i) for i in input().split())  
ks = [[int(i) for i in input().split()] for i in range(m)] 
p = [int(i) for i in input().split()]

k_list = []
count_switch = [0] * n

for i in range(m):
  k = int(ks[i][0])
  k_list.append(k)
  for j in range(k):
  	count_switch[ks[i][j+1]-1] += 1

ans = 1
for k in k_list:
  ans *= math.pow(2, k-1)
  
for c in count_switch:
  if c > 1:
    ans /= math.pow(2, c-1)
  elif c == 0:
    ans *= 2
print(int(ans))