#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 7;
pair<int, int> q[N];
int n, m, fa[N << 1], a[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = !read();
  for (int i = 1; i <= m; i++) fa[i] = i, fa[i + m] = i + m;
  for (int i = 1; i <= m; i++) {
    int opt = read();
    for (int j = 1; j <= opt; j++) {
      int v = read();
      if (!q[v].first)
        q[v].first = i;
      else
        q[v].second = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    int x1 = find(q[i].first), x2 = find(q[i].first + m);
    int y1 = find(q[i].second), y2 = find(q[i].second + m);
    if (a[i]) {
      fa[x1] = y2;
      x2 = find(x2), y1 = find(y1);
      fa[x2] = y1;
    } else {
      fa[x1] = y1;
      x2 = find(x2), y2 = find(y2);
      fa[x2] = y2;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (find(i) == find(i + m)) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
}
