#include <bits/stdc++.h>
using namespace std;
vector<int> dr[100005], sw[100005];
int n, m, an, a[100005], sl1[100005], sl2[100005], dv1[100005], dv2[100005];
void dfs1(int x, int fl) {
  if (an) return;
  if (!fl) {
    for (int i = 0; i < sw[x].size(); i++)
      if (!dv1[sw[x][i]]) dfs1(sw[x][i], 1 - fl);
  } else {
    dv1[x] = 1;
    if (!sl1[dr[x][0]]) {
      sl1[dr[x][0]] = sl1[dr[x][1]];
      if (!a[x]) sl1[dr[x][0]] = sl1[dr[x][0]] % 2 + 1;
      dfs1(dr[x][0], 1 - fl);
    } else if (!sl1[dr[x][1]]) {
      sl1[dr[x][1]] = sl1[dr[x][0]];
      if (!a[x]) sl1[dr[x][1]] = sl1[dr[x][1]] % 2 + 1;
      dfs1(dr[x][1], 1 - fl);
    } else {
      if (a[x] == 1 && sl1[dr[x][0]] != sl1[dr[x][1]]) an = 1;
      if (a[x] == 0 && sl1[dr[x][0]] == sl1[dr[x][1]]) an = 1;
    }
  }
}
int main() {
  int i, j, k, l;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= m; i++) {
    int t;
    cin >> t;
    while (t--) {
      cin >> j;
      sw[i].push_back(j);
      dr[j].push_back(i);
    }
  }
  for (i = 1; i <= n; i++)
    if (!dv1[i]) {
      an = 0;
      sl1[dr[i][0]] = 1;
      dfs1(dr[i][0], 0);
      if (an) break;
    }
  if (an)
    cout << "NO\n";
  else
    cout << "YES\n";
  return 0;
}
