#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, w;
  node *next;
};
int i, j, m, n, x, y;
int r[100005], con[100005][3], col[100005];
bool visit[100005], ans;
node *nd[100005];
void addd(int u, int v, int w) {
  node *p = new node();
  p->to = v;
  p->w = w;
  p->next = nd[u];
  nd[u] = p;
}
void dfs(int u, int pre) {
  visit[u] = true;
  node *p = nd[u];
  while (p) {
    int temp;
    if (p->w == 1)
      temp = 3 - col[u];
    else
      temp = col[u];
    if (col[p->to] == 0) {
      col[p->to] = temp;
      dfs(p->to, u);
    } else if (col[p->to] != temp)
      ans = false;
    p = p->next;
  }
}
int main() {
  ans = true;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &r[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &x);
    for (j = 1; j <= x; j++) {
      scanf("%d", &y);
      if (con[y][0] == 0)
        con[y][0] = i;
      else
        con[y][1] = i;
    }
  }
  for (i = 1; i <= n; i++) {
    if (r[i] == 0) {
      addd(con[i][0], con[i][1], 1);
      addd(con[i][1], con[i][0], 1);
    } else {
      addd(con[i][0], con[i][1], 0);
      addd(con[i][1], con[i][0], 0);
    }
  }
  for (i = 1; i <= m; i++) {
    if (!visit[i]) {
      col[i] = 1;
      dfs(i, -1);
    }
  }
  if (ans)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
