#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v;
  long long w;
};
long long MOD = 1000000007;
long long _MOD = 1000000009;
double EPS = 1e-10;
struct union_find {
  vector<int> v;
  union_find(int n) : v(n, -1) {}
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y];
    v[y] = x;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N);
  for (int i = 0; i < N; i++) scanf("%d", &a[i]);
  vector<vector<int> > G(N);
  for (int j = 0; j < M; j++) {
    int K;
    scanf("%d", &K);
    while (K--) {
      int i;
      scanf("%d", &i);
      i--;
      G[i].push_back(j);
    }
  }
  union_find uf(M * 2);
  for (int i = 0; i < N; i++) {
    int j1 = G[i][0], j2 = G[i][1];
    if (a[i])
      uf.unite(j1, j2), uf.unite(M + j1, M + j2);
    else
      uf.unite(j1, M + j2), uf.unite(M + j1, j2);
  }
  for (int j = 0; j < M; j++)
    if (uf.same(j, M + j)) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
}
