#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
double mini = 0.000000001;
double Det(vector<vector<double>> a) {
  bool b;
  vector<double> c;
  double d;
  for (long long i = 0; i < a.size(); i++) {
    if (abs(a[i][i]) < mini) {
      b = false;
      for (long long j = i + 1; j < a.size(); j++) {
        if (abs(a[j][i]) > mini && b == false) {
          c = a[j];
          a[j] = a[i];
          a[i] = c;
          b = true;
          j = a.size();
        }
      }
      if (b == false) return 0;
    }
    for (long long j = i + 1; j < a.size(); j++) {
      d = a[j][i] / a[i][i];
      for (long long k = i; k < a.size(); k++) {
        a[j][k] = a[j][k] - a[i][k] * d;
      }
    }
  }
  double ans = 1;
  for (long long i = 0; i < a.size(); i++) {
    ans *= a[i][i];
  }
  return ans;
}
long long Rank(vector<vector<double>> a) {
  bool b;
  double c;
  double d;
  long long l = 0;
  for (long long i = 0; i < a[0].size(); i++) {
    b = true;
    if (abs(a[l][i]) < mini) {
      b = false;
      for (long long j = l + 1; j < a.size(); j++) {
        if (abs(a[j][i]) > mini && b == false) {
          for (long long m = 0; m < a[j].size(); m++) {
            c = a[j][m];
            a[j][m] = a[l][m];
            a[l][m] = c;
          }
          b = true;
          j = a.size();
        }
      }
    }
    if (b == false) {
    } else {
      for (long long j = i + 1; j < a.size(); j++) {
        d = a[j][i] / a[i][i];
        for (long long k = i; k < a[0].size(); k++) {
          a[j][k] = a[j][k] - a[i][k] * d;
        }
      }
      l++;
      if (l >= a.size()) i = a[0].size();
    }
  }
  return l;
}
int main() {
  long long m, n;
  cin >> n >> m;
  vector<vector<double>> a(m);
  long long k[m];
  long long s[m][n];
  long long p[m];
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      a[i].push_back(0);
    }
  }
  for (long long i = 0; i < m; i++) {
    cin >> k[i];
    for (long long j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      a[i][s[i][j] - 1] = 1;
    }
  }
  for (long long i = 0; i < m; i++) {
    cin >> p[i];
  }
  long long ans = 1;
  long long r = Rank(a);
  for (long long i = 0; i < n - r; i++) {
    ans *= 2;
  }
  for (long long i = 0; i < m; i++) {
    a[i].push_back(p[i]);
  }
  long long rp = Rank(a);
  if (rp != r) ans = 0;
  cout << ans << endl;
  return 0;
}
