n,m = map(int,input().split()) #nがスイッチ、mが電球の数
s = []
swi = []

for i in range(m):
  x = list(map(int,input().split()))
  s.append(x)
p = list(map(int,input().split()))
print(s,p)

for i in range(1,2**n):
  x = format(i, 'b')
  x = x.zfill(n)
  swi.append(x)
#print(swi[-1])

for j in range(m):
  for i in range(len(swi)-1):
    x = 0
    for k in range(s[j][0]):
      x += int(swi[i][s[j][k]-1])
    if x % 2 != p[j]:
      del swi[i]
print(swi)