#include <bits/stdc++.h>
unsigned int CTZ(unsigned int arg) { return __builtin_ctz(arg); }
unsigned int CLZ(unsigned int arg) { return 31 - __builtin_clz(arg); }
static long long start_time = 0;
void swap_ds(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
typedef struct {
  int* data;
  int capacity;
  int size;
} Bucket;
void bucket_push(Bucket* b, int v) { b->data[b->size++] = v; }
int initial[110000];
int door_switches[110000 * 2];
int n, m;
int edge_data[110000 * 5];
Bucket E[110000 * 2];
int component[110000 * 2];
void dfs2(int i, int k) {
  component[i] = k;
  for (int j = 0; j < E[i].size; j++) {
    int w = E[i].data[j];
    if (component[w] == -1) {
      dfs2(w, k);
    }
  }
}
int main(int argc, char** argv) {
  start_time = time(0);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &initial[i]);
  }
  int* edge_data_ptr = edge_data;
  for (int i = 0; i < m; i++) {
    int cap;
    scanf("%d", &cap);
    E[i * 2].capacity = cap;
    E[i * 2].data = edge_data_ptr;
    edge_data_ptr += E[i * 2].capacity;
    E[i * 2 + 1].capacity = cap;
    E[i * 2 + 1].data = edge_data_ptr;
    edge_data_ptr += E[i * 2].capacity;
    for (int j = 0; j < cap; j++) {
      int x;
      scanf("%d", &x);
      int door = (x - 1) * 2;
      if (door_switches[door]) {
        door++;
      }
      door_switches[door] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    int a = door_switches[i * 2] * 2;
    int b = door_switches[i * 2 + 1] * 2;
    if (initial[i]) {
      bucket_push(&E[a], b);
      bucket_push(&E[b], a);
      bucket_push(&E[a + 1], b + 1);
      bucket_push(&E[b + 1], a + 1);
    } else {
      bucket_push(&E[a], b + 1);
      bucket_push(&E[b], a + 1);
      bucket_push(&E[a + 1], b);
      bucket_push(&E[b + 1], a);
    }
  }
  for (int i = 0; i < m * 2; i++) {
    if (E[i].size != E[i].capacity) printf("asd\n");
  }
  memset(component, -1, m * 2 * sizeof(int));
  for (int i = 0; i < m * 2; i++) {
    if (component[i] == -1) {
      dfs2(i, i);
    }
  }
  for (int i = 0; i < m; i++) {
    if (component[i * 2] == component[i * 2 + 1]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
