#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int n, m;   vector<int> d[MAXN];   int r[MAXN];   vector<pair<int, int> > g[MAXN];   inline void add_edge(int u, int v, int c) {     g[u].push_back(make_pair(c, v));     g[v].push_back(make_pair(c, u));   }   int col[MAXN];   inline bool dfs(int u, int c) {     if (col[u] != -1) return col[u] == c;     col[u] = c;     for (auto e : (g[u])) {       if (!dfs(e.second, c ^ e.first)) return 0;     }     return 1;   }   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     read(n);     read(m);     for (int i = (1); i <= (n); ++i) read(r[i]);     for (int i = (1); i <= (m); ++i) {       int x;       read(x);       for (int j = (1); j <= (x); ++j) {         int p;         read(p);         d[p].push_back(i);       }     }     for (int i = (1); i <= (n); ++i) add_edge(d[i][0], d[i][1], r[i] ^ 1);     memset(col, -1, sizeof col);     bool ans = 1;     for (int i = 1; i <= m && ans; ++i)       if (col[i] == -1) ans &= dfs(i, 0);     cout << (ans ?  YES  :  NO ) <<   n ;     return 0;   }   