#include <algorithm>
#include <bits/stdc++.h>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <vector>

// lib/bitcount.hpp
#ifndef BITCOUNT_HPP
#define BITCOUNT_HPP


namespace tools {
  std::uint32_t bitcount(std::uint32_t x);
  std::uint64_t bitcount(std::uint64_t x);
}

#endif

// lib/pow2.hpp
#ifndef POW2_HPP
#define POW2_HPP

/*
usage:

tools::pow2(5) => 32
*/


namespace tools {
  template <typename T, typename std::enable_if<std::is_unsigned<T>::value, std::nullptr_t>::type = nullptr>
  constexpr T pow2(const T x) {
    return static_cast<T>(1) << x;
  }

  template <typename T, typename std::enable_if<std::is_signed<T>::value, std::nullptr_t>::type = nullptr>
  constexpr T pow2(const T x) {
    return static_cast<T>(static_cast<typename std::make_unsigned<T>::type>(1) << static_cast<typename std::make_unsigned<T>::type>(x));
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/bitcount.cpp

namespace tools {
  std::uint32_t bitcount(std::uint32_t x) {
    x = (x & static_cast<std::uint32_t>(0x55555555ull)) + (x >> static_cast<std::uint32_t>(1) & static_cast<std::uint32_t>(0x55555555ull));
    x = (x & static_cast<std::uint32_t>(0x33333333ull)) + (x >> static_cast<std::uint32_t>(2) & static_cast<std::uint32_t>(0x33333333ull));
    x = (x & static_cast<std::uint32_t>(0x0f0f0f0full)) + (x >> static_cast<std::uint32_t>(4) & static_cast<std::uint32_t>(0x0f0f0f0full));
    x = (x & static_cast<std::uint32_t>(0x00ff00ffull)) + (x >> static_cast<std::uint32_t>(8) & static_cast<std::uint32_t>(0x00ff00ffull));
    return (x & static_cast<std::uint32_t>(0x0000ffffull)) + (x >> static_cast<std::uint32_t>(16) & static_cast<std::uint32_t>(0x0000ffffull));
  }

  std::uint64_t bitcount(std::uint64_t x) {
    x = (x & static_cast<std::uint64_t>(0x5555555555555555ull)) + (x >> static_cast<std::uint64_t>(1) & static_cast<std::uint64_t>(0x5555555555555555ull));
    x = (x & static_cast<std::uint64_t>(0x3333333333333333ull)) + (x >> static_cast<std::uint64_t>(2) & static_cast<std::uint64_t>(0x3333333333333333ull));
    x = (x & static_cast<std::uint64_t>(0x0f0f0f0f0f0f0f0full)) + (x >> static_cast<std::uint64_t>(4) & static_cast<std::uint64_t>(0x0f0f0f0f0f0f0f0full));
    x = (x & static_cast<std::uint64_t>(0x00ff00ff00ff00ffull)) + (x >> static_cast<std::uint64_t>(8) & static_cast<std::uint64_t>(0x00ff00ff00ff00ffull));
    x = (x & static_cast<std::uint64_t>(0x0000ffff0000ffffull)) + (x >> static_cast<std::uint64_t>(16) & static_cast<std::uint64_t>(0x0000ffff0000ffffull));
    return (x & static_cast<std::uint64_t>(0x00000000ffffffffull)) + (x >> static_cast<std::uint64_t>(32) & static_cast<std::uint64_t>(0x00000000ffffffffull));
  }
}

// main.cpp

class light_bulb {
public:
  i64 mask, condition;
};

int main() {
  i64 N, M;
  std::cin >> N >> M;
  std::vector<light_bulb> light_bulbs(M);
  for (i64 i = 0; i < M; ++i) {
    i64 k_i;
    std::cin >> k_i;
    light_bulbs[i].mask = 0;
    for (i64 j = 0; j < k_i; ++j) {
      i64 s_ij;
      std::cin >> s_ij;
      --s_ij;
      light_bulbs[i].mask |= tools::pow2(s_ij);
    }
  }
  for (i64 i = 0; i < M; ++i) {
    std::cin >> light_bulbs[i].condition;
  }

  i64 answer = 0;
  for (i64 state = 0; state < tools::pow2(N); ++state) {
    if (std::all_of(light_bulbs.begin(), light_bulbs.end(), [&state](const light_bulb& light_bulb) {
      return static_cast<i64>(tools::bitcount(static_cast<std::uint64_t>(state & light_bulb.mask))) % 2 == light_bulb.condition;
    })) {
      ++answer;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256