N, M = gets.split.map(&:to_i)

sp = []

pattern = []
0.upto((2 ** N) - 1) do |i|
  pattern << format("%0#{N}d", i.to_s(2).to_i)
end

M.times do
  d = gets.split.map(&:to_i)
  d.shift
  sp << d
end
pt = gets.split.map(&:to_i)

rs = Array.new(M) {
  Array.new
}
sp.each_with_index do |d, idx|
  pattern.each do |ptn|
    rn = 0
    d.each do |dn|
      rn += ptn[dn-1].to_i
    end
    if rn.odd? && pt[idx] == 1
      rs[idx] << ptn
    elsif rn.even? && pt[idx] == 0
      rs[idx] << ptn
    end
  end
end

result = rs[0]
rs.each do |r|
  result = result & r
end
p result.size