#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[10][10];
int p[10];
bool check_lump(int number, int s1, int s2, int s3, int s4, int s5, int s6,
                int s7, int s8, int s9, int s10) {
  if ((s[number][0] * s1 + s[number][1] * s2 + s[number][2] * s3 +
       s[number][3] * s4 + s[number][4] * s5 + s[number][5] * s6 +
       s[number][6] * s7 + s[number][7] * s8 + s[number][8] * s9 +
       s[number][9] * s10) %
          2 ==
      p[number]) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int count = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      s[i][j] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int temp;
      cin >> temp;
      s[i][temp - 1] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  for (int s1 = 0; s1 <= 1; s1++) {
    for (int s2 = 0; s2 <= 1; s2++) {
      for (int s3 = 0; s3 <= 1; s3++) {
        for (int s4 = 0; s4 <= 1; s4++) {
          for (int s5 = 0; s5 <= 1; s5++) {
            for (int s6 = 0; s6 <= 1; s6++) {
              for (int s7 = 0; s7 <= 1; s7++) {
                for (int s8 = 0; s8 <= 1; s8++) {
                  for (int s9 = 0; s9 <= 1; s9++) {
                    for (int s10 = 0; s10 <= 1; s10++) {
                      bool check = true;
                      for (int i = 0; i < m; i++) {
                        if (check_lump(i, s1, s2, s3, s4, s5, s6, s7, s8, s9,
                                       10) == false) {
                          check = false;
                          break;
                        }
                      }
                      if (check) {
                        count++;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  int div = 1;
  for (int i = 0; i < 10 - n; i++) {
    div *= 2;
  }
  cout << count / div << endl;
}
