#include <bits/stdc++.h>
using namespace std;
namespace zzc {
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 5;
int fa[maxn << 1], v[maxn];
int n, m;
vector<int> to[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  if (fx != fy) fa[fy] = fx;
}
void work() {
  int a, b;
  n = read();
  m = read();
  for (int i = 1; i <= (m << 1); i++) fa[i] = i;
  for (int i = 1; i <= n; i++) v[i] = read();
  for (int i = 1; i <= m; i++) {
    a = read();
    for (int j = 1; j <= a; j++) {
      b = read();
      to[b].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (v[i]) {
      merge(to[i][0], to[i][1]);
      merge(to[i][0] + m, to[i][1] + m);
    } else {
      merge(to[i][0], to[i][1] + m);
      merge(to[i][0] + m, to[i][1]);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (find(i) == find(i + m)) {
      printf("NO\n");
      return;
    }
  }
  printf("YES\n");
}
}  // namespace zzc
int main() {
  zzc::work();
  return 0;
}
