#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, z, cnt, sum, num, ans;
long long door[200005];
long long sw[200005][3];
long long f[200005 * 2];
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!('0' <= c && c <= '9')) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (('0' <= c && c <= '9')) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long find(long long h) {
  if (f[h] == h) return h;
  return f[h] = find(f[h]);
}
int main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) door[i] = read();
  for (long long i = 1; i <= m; i++) {
    cnt = read();
    while (cnt--) {
      x = read();
      sw[x][++sw[x][0]] = i;
    }
  }
  for (long long i = 1; i <= m * 2; i++) f[i] = i;
  for (long long i = 1; i <= n; i++)
    if (door[i]) {
      f[find(sw[i][1])] = find(sw[i][2]);
      f[find(sw[i][1] + m)] = find(sw[i][2] + m);
    } else {
      f[find(sw[i][1])] = find(sw[i][2] + m);
      f[find(sw[i][1] + m)] = find(sw[i][2]);
    }
  for (long long i = 1; i <= m; i++)
    if (find(i) == find(i + m)) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
