N,M = gets.split.map &:to_i
switches = Array.new(N,0)
M.times{ |j|
  k,*s = gets.split.map &:to_i
  s.each{ |i| switches[i-1] += (1 << j) }
}
P = gets.split.reverse.join.to_i(2)
p (0...(1<<N)).count{ |s|
  t = 0
  (0...N).each{ |i|
    t ^= switches[i] if (s & (1 << i)) > 0
  }
  t == P 
}
