#include <bits/stdc++.h>
using namespace std;
const int MAT = 12;
struct Mat {
  long long v[MAT][MAT], n, m;
};
void matprint(Mat& a) {
  for (int i = 0; i < ((int)(a.n)); i++) {
    for (int j = 0; j < ((int)(a.m)); j++) cout << a.v[i][j] << " ";
    cout << endl;
  }
}
Mat mulmat(Mat& a, Mat& b, int n = MAT, int mod = 1e9 + 7) {
  Mat r;
  for (int x = 0; x < ((int)(n)); x++)
    for (int y = 0; y < ((int)(n)); y++) r.v[x][y] = 0;
  for (int x = 0; x < ((int)(n)); x++)
    for (int z = 0; z < ((int)(n)); z++)
      for (int y = 0; y < ((int)(n)); y++) {
        r.v[x][y] += a.v[x][z] * b.v[z][y];
        if (r.v[x][y] > mod) r.v[x][y] -= mod;
      }
  for (int x = 0; x < ((int)(n)); x++)
    for (int y = 0; y < ((int)(n)); y++) r.v[x][y] %= mod;
  return r;
}
Mat powmat(long long p, Mat a, int n = MAT) {
  Mat r;
  for (int x = 0; x < ((int)(n)); x++)
    for (int y = 0; y < ((int)(n)); y++) r.v[x][y] = 0;
  for (int i = 0; i < ((int)(n)); i++) r.v[i][i] = 1;
  while (p) {
    if (p % 2) r = mulmat(r, a, n);
    a = mulmat(a, a, n);
    p >>= 1;
  }
  return r;
}
int matrank(Mat& a, long long(inverse)(long long, long long),
            long long mod = 2) {
  int ans = min(a.n, a.m);
  for (int i = 0; i < ((int)(a.n)); i++) {
    int max_id = -1;
    for (int j = ((int)(i)); j <= ((int)(a.n - 1)); j++) {
      if (a.v[j][i] != 0) {
        if (max_id == -1 || a.v[max_id][i] < a.v[j][i]) {
          max_id = j;
        }
      }
    }
    if (max_id == -1) {
      ans = i;
      break;
    }
    if (i != max_id)
      for (int j = ((int)(i)); j <= ((int)(a.m - 1)); j++)
        swap(a.v[i][j], a.v[max_id][j]);
    for (int j = ((int)(i + 1)); j <= ((int)(a.n - 1)); j++) {
      long long inv = (a.v[j][i] * inverse(a.v[i][i], mod)) % mod;
      for (int k = ((int)(i)); k <= ((int)(a.n - 1)); k++) {
        a.v[j][k] += inv * a.v[i][k];
        a.v[j][k] %= mod;
      }
    }
  }
  return ans;
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
long long invmod(long long a, long long mod) {
  long long x, y;
  extGCD(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}
long long n, m, k[11], s[11][11], p[11], ans = 0, mod = 2;
Mat mt;
void init() {
  cin >> n >> m;
  for (int i = 0; i < ((int)(m)); i++)
    for (int j = 0; j < ((int)(n + 1)); j++) mt.v[i][j] = 0;
  for (int i = 0; i < ((int)(m)); i++) {
    cin >> k[i];
    for (int j = 0; j < ((int)(k[i])); j++) {
      cin >> s[i][j];
      s[i][j]--;
      mt.v[i][s[i][j]] = 1;
    }
  }
  for (int i = 0; i < ((int)(m)); i++) {
    cin >> p[i];
    mt.v[i][n] = p[i] % mod;
  }
  mt.n = m;
  mt.m = n + 1;
}
int main(void) {
  init();
  long long t = n - matrank(mt, invmod, mod);
  cout << (t >= 0 ? (1 << t) : 0) << endl;
  return 0;
}
