#include <bits/stdc++.h>
using namespace std;
struct pp {
  int val;
  int same;
};
vector<pp> with[100005];
vector<int> v[100005];
int color[100005];
int currcolor[100005];
bool ending = false;
void dfs(int parent, int curr) {
  if (ending == true) return;
  for (int i = 1; i <= with[curr][0].val; i++) {
    if (ending == true) return;
    if (with[curr][i].val == parent) continue;
    int vertex = with[curr][i].val;
    if ((currcolor[vertex] != -1) &&
        ((currcolor[vertex] + currcolor[curr] + with[curr][i].same) % 2 == 0)) {
      cout << "NO\n";
      ending = true;
      return;
    }
    if (currcolor[vertex] != -1) continue;
    if (with[curr][i].same == 1)
      currcolor[vertex] = currcolor[curr];
    else
      currcolor[vertex] = 1 - currcolor[curr];
    dfs(curr, vertex);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  pp nullpp;
  nullpp.val = 0, nullpp.same = 0;
  for (int i = 1; i <= m; i++) with[i].push_back(nullpp);
  for (int i = 1; i <= n; i++) cin >> color[i];
  for (int i = 1; i <= m; i++) {
    int k, val;
    cin >> k;
    for (int j = 1; j <= k; j++) {
      cin >> val;
      v[val].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    with[v[i][0]][0].val++;
    pp ed;
    ed.val = v[i][1];
    ed.same = color[i];
    with[v[i][0]].push_back(ed);
    with[v[i][1]][0].val++;
    ed.val = v[i][0];
    with[v[i][1]].push_back(ed);
  }
  for (int i = 1; i <= m; i++) currcolor[i] = -1;
  for (int i = 1; i <= m; i++)
    if (currcolor[i] == -1) {
      currcolor[i] = 1;
      dfs(-1, i);
    }
  if (ending == false) cout << "YES\n";
}
