#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn];
vector<int> g[maxn];
vector<int> f[maxn];
int col[maxn];
bool vis[maxn];
queue<int> q;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    while (x--) {
      int u;
      cin >> u;
      f[u].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int u = f[i][0], v = f[i][1];
    g[u].push_back(a[i]);
    g[u].push_back(v);
    g[v].push_back(a[i]);
    g[v].push_back(u);
  }
  for (int o = 1; o <= m; o++) {
    if (vis[o] or g[o].empty()) continue;
    q.push(o);
    col[o] = 1;
    vis[0] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < g[u].size(); i += 2) {
        int v = g[u][i + 1];
        int w = g[u][i];
        if (!vis[v]) {
          vis[v] = true;
          if (w == 1)
            col[v] = col[u];
          else
            col[v] = 1 - col[u];
          q.push(v);
        } else {
          int t = col[v];
          if ((w == 1 and t != col[u]) or (w == 0 and t == col[u])) {
            cout << "NO\n";
            return 0;
          }
        }
      }
    }
  }
  cout << "YES\n";
  return 0;
}
