#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
int r[maxn];
vector<int> f[maxn];
vector<pair<int, int> > g[maxn];
queue<int> q;
int c[maxn];
void bfs(int i) {
  q.push(i);
  c[i] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto v : g[x]) {
      int u = v.first;
      int y = v.second;
      if (c[u] != -1) continue;
      if (y == 1)
        c[u] = c[x];
      else
        c[u] = 1 - c[x];
      q.push(u);
    }
  }
}
bool check() {
  for (int i = 1; i <= n; i++) {
    int u = f[i][0];
    int v = f[i][1];
    if (r[i] == 1 && c[u] != c[v]) return 0;
    if (r[i] == 0 && c[u] == c[v]) return 0;
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
  for (int i = 1; i <= m; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      f[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int u = f[i][0];
    int v = f[i][1];
    g[u].push_back({v, r[i]});
    g[v].push_back({u, r[i]});
  }
  memset(c, -1, sizeof(c));
  for (int i = 1; i <= m; i++)
    if (c[i] == -1) bfs(i);
  if (check())
    puts("YES");
  else
    puts("NO");
  return 0;
}
