#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct Edge {
  int u;
  int v;
} edge[MAXN];
struct lamp {
  int num;
  int state;
} l[MAXN];
vector<lamp> g[MAXN];
vector<int> edges[MAXN];
queue<int> q;
int a[MAXN], visit[MAXN], color[MAXN];
int main() {
  int i, j, k, n, m, x, y, numedge = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= m; i++) {
    scanf("%d", &x);
    for (j = 1; j <= x; j++) {
      scanf("%d", &y);
      edges[y].push_back(i);
    }
  }
  for (i = 1; i <= n; i++) {
    lamp temp;
    temp.num = edges[i][0];
    temp.state = a[i];
    g[edges[i][1]].push_back(temp);
    temp.num = edges[i][1];
    temp.state = a[i];
    g[edges[i][0]].push_back(temp);
  }
  for (k = 1; k <= m; k++) {
    if (visit[k]) continue;
    q.push(k);
    visit[k] = 1;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (i = 0; i < g[now].size(); i++) {
        int to = g[now][i].num;
        int statenow = g[now][i].state;
        if (!visit[to]) {
          q.push(to);
          visit[to] = 1;
          if (statenow == 1)
            color[to] = color[now];
          else
            color[to] = !color[now];
        } else {
          if (statenow == 1) {
            if (color[to] != color[now]) {
              printf("NO\n");
              return 0;
            }
          } else {
            if (color[to] == color[now]) {
              printf("NO\n");
              return 0;
            }
          }
        }
      }
    }
  }
  printf("YES\n");
  return 0;
}
