#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v, nxt, w;
} edge[200010 * 2];
int col[200010], fir[200010], sec[200010], head[200010], tot, w[200010];
void Add(int u, int v, int w) {
  edge[tot] = (Edge){v, head[u], w};
  head[u] = tot++;
  edge[tot] = (Edge){u, head[v], w};
  head[v] = tot++;
}
bool dfs(int u) {
  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int v = edge[i].v, w = edge[i].w;
    if (col[v] == -1) {
      col[v] = col[u] ^ w;
      if (!dfs(v)) return false;
    } else if (col[u] ^ col[v] ^ w)
      return false;
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]), w[i] ^= 1;
  for (int i = 1; i <= m; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int a;
      scanf("%d", &a);
      if (fir[a] == 0)
        fir[a] = i;
      else
        sec[a] = i;
    }
  }
  memset(head, -1, sizeof(head));
  tot = 0;
  for (int i = 1; i <= n; i++) Add(fir[i], sec[i], w[i]);
  memset(col, -1, sizeof(col));
  bool flag = 1;
  for (int i = 1; i <= m; i++) {
    if (col[i] == -1) {
      col[i] = 0;
      if (!dfs(i)) {
        flag = 0;
        break;
      }
    }
  }
  if (!flag)
    puts("NO");
  else
    puts("YES");
  return 0;
}
