#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, x;
  scanf("%d %d", &n, &m);
  int a[n + 1];
  vector<int> edge[n + 1];
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= m; i++) {
    scanf("%d", &x);
    for (j = 1; j <= x; j++) {
      scanf("%d", &k);
      edge[k].push_back(i);
    }
  }
  vector<vector<pair<int, int> > > graph(m + 1, vector<pair<int, int> >());
  for (i = 1; i <= n; i++) {
    graph[edge[i][0]].push_back(pair<int, int>(edge[i][1], a[i]));
    graph[edge[i][1]].push_back(pair<int, int>(edge[i][0], a[i]));
  }
  vector<int> parity(m + 1, -1), vis(m + 1, 0);
  queue<int> q;
  bool check = true;
  for (i = 1; i <= m; i++) {
    if (vis[i] == 0 && !graph[i].empty()) {
      parity[i] = 0;
      vis[i] = 1;
      q.push(i);
      while (!q.empty()) {
        x = q.front();
        q.pop();
        for (auto j : graph[x]) {
          int par = parity[x];
          if (j.second == 0) par = 1 - par;
          if (vis[j.first] == 1 && parity[j.first] != par) check = false;
          if (vis[j.first] == 0) {
            parity[j.first] = par;
            vis[j.first] = 1;
            q.push(j.first);
          }
        }
      }
    }
  }
  if (check == false)
    printf("NO");
  else
    printf("YES");
}
