package main

import (
	"fmt"
	"math"
	"math/bits"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	bulbs := make([][]int, M)
	bulbs2 := make([]int, M)
	for i := 0; i < M; i++ {
		var k int
		fmt.Scan(&k)
		bulbs[i] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&bulbs[i][j])
			bulbs2[i] += 1 << uint(bulbs[i][j]-1)
		}
	}
	p := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&p[i])
	}

	// O(1024)
	ans := 0
	for i := 0; i < int(math.Pow(2, float64(N))); i++ {
		oncount := 0
		for j := 0; j < M; j++ {
			count := bits.OnesCount(uint(bulbs2[j] & i))
			if (count+p[j])%2 == 0 {
				oncount++
			}
		}
		if oncount == M {
			ans++
			fmt.Println(i)
		}
	}
}
