#include <bits/stdc++.h>
using namespace std;
int n, m, fa[1000005], b[1000005], key[2][1000005], cnt[1000005];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (m << 1); i++) fa[i] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d", &x);
    while (x--) {
      scanf("%d", &y);
      key[cnt[y]++][y] = i;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!b[i]) {
      fa[find(key[0][i])] = find(key[1][i] + m);
      fa[find(key[1][i])] = find(key[0][i] + m);
    } else {
      fa[find(key[0][i])] = find(key[1][i]);
      fa[find(key[1][i] + m)] = find(key[0][i] + m);
    }
  for (int i = 1; i <= m; i++)
    if (find(i) == find(i + m)) return puts("NO"), 0;
  puts("YES");
}
