#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], vis[100005], vis2[100005], val[100005], inv;
vector<pair<int, int> > g[100005];
void dfs(int i) {
  vis[i] = 1;
  for (int j = 0; j < g[i].size(); j++) {
    int ch = g[i][j].first;
    int flag = g[i][j].second;
    if (!vis[ch]) {
      val[ch] = val[i] ^ (1 - flag);
      dfs(ch);
    } else {
      if (val[ch] != (val[i] ^ (1 - flag))) inv = 1;
    }
  }
}
void dfs2(int i) {
  vis2[i] = 1;
  for (int j = 0; j < g[i].size(); j++) {
    int ch = g[i][j].first;
    int flag = g[i][j].second;
    if (!vis2[ch]) {
      val[ch] = val[i] ^ (1 - flag);
      dfs2(ch);
    } else {
      if (val[ch] != (val[i] ^ (1 - flag))) inv = 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < m + 1; i++) {
    int x;
    cin >> x;
    for (int j = 1; j < x + 1; j++) {
      int r;
      cin >> r;
      if (b[r] == 0)
        b[r] = i;
      else {
        g[i].push_back(make_pair(b[r], a[r]));
        g[b[r]].push_back(make_pair(i, a[r]));
      }
    }
  }
  for (int i = 1; i < m + 1; i++) {
    if (!vis[i]) {
      val[i] = 1;
      dfs(i);
    }
    if (inv) break;
    if (!vis2[i]) {
      val[i] = 0;
      dfs2(i);
    }
    if (inv) break;
  }
  if (inv)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
