#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > e[100010];
int vis[100010], p[100010], c[100010], vis2[100010];
struct P {
  int v, col;
  P() {}
  P(int _v, int _c) : v(_v), col(_c) {}
};
bool bfs(int st, int col) {
  c[st] = col;
  vis2[st] = 1;
  queue<P> que;
  que.push(P(st, col));
  while (!que.empty()) {
    P now = que.front();
    que.pop();
    int Size = e[now.v].size();
    for (int i = 0; i < Size; i++) {
      pair<int, int> Next = e[now.v][i];
      int tmp = Next.second;
      int tmp2 = (tmp == 1 ? now.col : !now.col);
      if (c[Next.first] != -1) {
        if (c[Next.first] != tmp2)
          return false;
        else
          continue;
      } else
        c[Next.first] = tmp2;
      vis2[Next.first] = 1;
      que.push(P(Next.first, tmp2));
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i < n + 1; i++) scanf("%d", &vis[i]);
  for (int i = 1; i < m + 1; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j < cnt + 1; j++) {
      int u;
      scanf("%d", &u);
      if (!p[u])
        p[u] = i;
      else {
        e[i].push_back(make_pair(p[u], vis[u]));
        e[p[u]].push_back(make_pair(i, vis[u]));
      }
    }
  }
  int flag = 1;
  memset(c, -1, sizeof(c));
  for (int i = 1; i < m + 1; i++) {
    if (!vis2[i]) flag = bfs(i, 1);
    if (!flag) break;
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
}
