import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  val graph = Array.ofDim[Boolean](m,n)
  val ki = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt - 1))
    .toArray
  val p = in.readLine.split(" ").map(_.toInt)

  for {
    i <- 0 until m
    j <- 0 until ki(i)(0) + 1
  } {
    graph(i)(ki(i)(j)) = true
  }

  val table = Array.ofDim[Int](m,n)
  val res = Array.ofDim[Int](m)
  for {
    i <- 0 until m
    j <- 0 until n
    k <- 0 until 2
  } {
    table(i)(j) = k
    if(graph(i)(j) && table(i).count(_ == 1) != 0 && (table(i).count(_ == 1) % 2) == p(i)) res(i) += 1
  }

  // println(res.mkString(" "))
  val ans = res.product
  println(ans)
}