#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int m[10][11];
  for (int i = 0; i < (int)(10); i++) {
    for (int j = 0; j < (int)(11); j++) m[i][j] = 12;
  }
  int ans1;
  for (int i = 0; i < (int)(M); i++) {
    int k;
    cin >> k;
    for (int j = 0; j < (int)(k); j++) {
      cin >> m[i][j];
    }
  }
  for (int i = 0; i < (int)(M); i++) cin >> m[i][10];
  int ans = 0;
  int jud = 0;
  int light[10];
  for (int a = 0; a < (int)(2); a++) {
    light[0] = a;
    for (int b = 0; b < (int)(2); b++) {
      light[1] = b;
      for (int c = 0; c < (int)(2); c++) {
        light[2] = c;
        for (int d = 0; d < (int)(2); d++) {
          light[3] = d;
          for (int e = 0; e < (int)(2); e++) {
            light[4] = e;
            for (int f = 0; f < (int)(2); f++) {
              light[5] = f;
              for (int g = 0; g < (int)(2); g++) {
                light[6] = g;
                for (int h = 0; h < (int)(2); h++) {
                  light[7] = h;
                  for (int i = 0; i < (int)(2); i++) {
                    light[8] = i;
                    for (int j = 0; j < (int)(2); j++) {
                      light[9] = j;
                      ans1 = 0;
                      for (int p = 0; p < (int)(M); p++) {
                        jud = 0;
                        for (int q = 0; q < (int)(10); q++) {
                          if (m[p][q] != 12) jud += light[10 - m[p][q]];
                        }
                        if (jud % 2 == m[p][10]) ans1++;
                      }
                      if (ans1 == M) ans++;
                    }
                    if (M < 2) break;
                  }
                  if (M < 3) break;
                }
                if (M < 4) break;
              }
              if (M < 5) break;
            }
            if (M < 6) break;
          }
          if (M < 7) break;
        }
        if (M < 8) break;
      }
      if (M < 9) break;
    }
    if (M < 10) break;
  }
  cout << ans << endl;
}
