#include <bits/stdc++.h>
using namespace std;
vector<int> v[100010];
vector<pair<int, int> > g[100010];
int r[100010];
int col[100010];
bool bad;
void dfs(int x) {
  if (bad) return;
  for (auto i : g[x]) {
    int j = i.first;
    int k = i.second;
    if (col[j] == -1) {
      col[j] = col[x] ^ k;
      dfs(j);
    } else if (col[j] != col[x] ^ k) {
      bad = true;
      return;
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &r[i]);
  }
  for (int i = 1; i <= m; i++) {
    int d;
    scanf("%d", &d);
    while (d--) {
      int x;
      scanf("%d", &x);
      v[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int p = v[i][0];
    int q = v[i][1];
    if (r[i] == 0) {
      g[p].push_back(pair<int, int>(q, 1));
      g[q].push_back(pair<int, int>(p, 1));
    } else {
      g[p].push_back(pair<int, int>(q, 0));
      g[q].push_back(pair<int, int>(p, 0));
    }
  }
  memset(col, -1, sizeof col);
  bad = false;
  for (int i = 1; i <= m; i++) {
    if (col[i] == -1) {
      col[i] = 0;
      dfs(i);
    }
    if (bad) break;
  }
  if (!bad)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
