#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int p[m];
  memset(s, 0, sizeof(int) * m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int si;
      cin >> si;
      s[i] |= (1 << (si - 1));
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int res_cnt = 0;
  for (int i = 0; i < (1 << n); i++) {
    int on_cnt = 0;
    for (int j = 0; j < m; j++) {
      if (((0x0000ffff &
            ((0x00ff00ff &
              ((0x0f0f0f0f &
                ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                 ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                 ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                  2))) +
               ((0xf0f0f0f0 &
                 ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                 ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                  ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                  ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                   2))) >>
                4))) +
             ((0xff00ff00 &
               ((0x0f0f0f0f &
                 ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                 ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                  ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                  ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                   2))) +
                ((0xf0f0f0f0 &
                  ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                  ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                   ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                   ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                    2))) >>
                 4))) >>
              8))) +
               ((0xffff0000 &
                 ((0x00ff00ff &
                   ((0x0f0f0f0f &
                     ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                     ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                      ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                      ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                       2))) +
                    ((0xf0f0f0f0 &
                      ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                      ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                       ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                       ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                        2))) >>
                     4))) +
                  ((0xff00ff00 &
                    ((0x0f0f0f0f &
                      ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                      ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                       ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                       ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                        2))) +
                     ((0xf0f0f0f0 &
                       ((0x33333333 & ((0x55555555 & (i & s[j])) +
                                       ((0xaaaaaaaa & (i & s[j])) >> 1))) +
                        ((0xcccccccc & ((0x55555555 & (i & s[j])) +
                                        ((0xaaaaaaaa & (i & s[j])) >> 1))) >>
                         2))) >>
                      4))) >>
                   8))) >>
                16) &
           1) == p[j]) {
        on_cnt++;
      }
    }
    if (on_cnt == m) {
      res_cnt++;
    }
  }
  cout << res_cnt << endl;
  return 0;
}
