#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infL = LLONG_MAX;
struct psychotronic_induction {
  int electromagnetic_wave = 7;
};
const int nmax = 1e5 + 10;
int n, m, a[nmax];
;
int s[nmax], used[nmax];
vector<int> g[nmax];
pair<int, int> edge[nmax];
int second_node(int idx, int node) {
  return (edge[idx].first == node) ? edge[idx].second : edge[idx].first;
}
bool dfs(int node, int curr = 0) {
  s[node] ^= curr;
  used[node] = 1;
  for (auto &it : g[node]) {
    if (used[second_node(it, node)]) {
      if (s[second_node(it, node)] != 1 ^ a[it] ^ s[node]) return 0;
      continue;
    }
    s[second_node(it, node)] = 1 ^ a[it] ^ s[node];
    if (!dfs(second_node(it, node))) return 0;
  }
  return 1;
}
void mark(int node, int s) {
  used[node] = s;
  for (auto &it : g[node]) {
    if (used[second_node(it, node)] == s) continue;
    mark(second_node(it, node), s);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= m; ++i) {
    int nr;
    scanf("%d", &nr);
    for (int j = 1; j <= nr; ++j) {
      int x;
      scanf("%d", &x);
      if (!edge[x].first)
        edge[x].first = i;
      else
        edge[x].second = i;
    }
  }
  swap(n, m);
  for (int i = 1; i <= m; ++i)
    g[edge[i].first].push_back(i), g[edge[i].second].push_back(i);
  for (int i = 1; i <= n; ++i) {
    if (used[i]) continue;
    if (!dfs(i, 0)) {
      mark(i, 0);
      if (!dfs(i, 1)) {
        printf("NO\n");
        return 0;
      }
    }
    mark(i, 1);
  }
  printf("YES\n");
  return 0;
}
