import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def numWithNbits(n: Int): Int = (1 << n) - 1
  def checkBitOn(n: Int, b: Int): Int = (n >> (b - 1)) & 1
  def countBitsOn(n: Int, bl: List[Int]): Int = bl match {
    case Nil => 0
    case bh::bt => checkBitOn(n, bh) + countBitsOn(n, bt)
  }

  def isAllOn(n: Int, is: List[(List[Int], Int)]): Boolean = is match {
    case Nil => true
    case (bits, parity) :: irs =>
      if (countBitsOn(n, bits) % 2 != parity) false
      else isAllOn(n, irs)
  }

  def solve(input: String): String = {
    val s: Scanner = new Scanner(input)
    val (n, m) = (s.nextInt, s.nextInt)
    val ks = List.fill(m)(List.fill(s.nextInt)(s.nextInt))
    val ps = List.fill(m)(s.nextInt)
    val is = ks.zip(ps)
    (1 to numWithNbits(n)).count(i => isAllOn(i, is)).toString()
  }

  val tests = List(
    """2 2
      |2 1 2
      |1 2
      |0 1
    """.stripMargin -> """1""",
    """2 1
      |2 1 2
      |0
    """.stripMargin -> """1""",
    """2 3
      |2 1 2
      |1 1
      |1 2
      |0 0 1
    """.stripMargin -> """0""",
    """5 2
      |3 1 2 5
      |2 2 3
      |1 0
    """.stripMargin -> "8"
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}