#include <bits/stdc++.h>
using namespace std;
int n, m;
int door_opened[100005];
vector<int> sw_to_rooms[100005];
int room_to_sw[100005][2];
int edge_switched[100005][2][2];
bool done[100005][2];
int switching[100005][2];
int other_switch(int room, int sw) {
  if (room_to_sw[room][0] == sw) return room_to_sw[room][1];
  return room_to_sw[room][0];
}
bool check_valid(int room, int k) {
  if (edge_switched[room][k][0] == -1 || edge_switched[room][k][1] == -1)
    return true;
  return ((edge_switched[room][k][0] ^ edge_switched[room][k][1] ^
           door_opened[room]) == 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); i++) {
    scanf("%d", &door_opened[i]);
    room_to_sw[i][0] = -1;
    for (int k = 0; k < (2); k++)
      edge_switched[i][k][0] = edge_switched[i][k][1] = -1;
  }
  for (int i = 0; i < (m); i++)
    for (int k = 0; k < (2); k++) switching[i][k] = -1;
  for (int i = 0; i < (m); i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < (k); j++) {
      int dr;
      scanf("%d", &dr);
      --dr;
      sw_to_rooms[i].push_back(dr);
      if (room_to_sw[dr][0] == -1)
        room_to_sw[dr][0] = i;
      else
        room_to_sw[dr][1] = i;
    }
  }
  queue<pair<int, int> > q;
  for (int i = 0; i < (m); i++) {
    if (done[i][0]) continue;
    bool success = false;
    for (int k = 0; k < (2); k++) {
      bool now_suc = true;
      q.push(make_pair(i, k));
      while (!q.empty()) {
        pair<int, int> now = q.front();
        q.pop();
        if (done[now.first][k]) {
          if (switching[now.first][k] != now.second) now_suc = false;
          continue;
        }
        done[now.first][k] = true;
        switching[now.first][k] = now.second;
        for (int j = 0; j < ((int)sw_to_rooms[now.first].size()); j++) {
          int door = sw_to_rooms[now.first][j];
          int kkk = 0;
          if (edge_switched[door][k][kkk] >= 0) kkk++;
          edge_switched[door][k][kkk] = now.second;
          if (kkk == 1) {
            if (!check_valid(door, k)) {
              now_suc = false;
            }
            continue;
          }
          int opened = door_opened[door] ^ now.second;
          q.push(make_pair(other_switch(door, now.first), opened ^ 1));
        }
      }
      while (!q.empty()) q.pop();
      if (now_suc) {
        success = true;
        break;
      }
    }
    if (!success) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
