#include <bits/stdc++.h>
using namespace std;
int r[100005], vis[100005], mila[100005];
vector<int> cont[100005];
vector<pair<int, int> > g[100005];
void fail() {
  cout << "NO";
  exit(0);
}
void dfs(int v, int color) {
  if (vis[v] == 1) {
    if (color != mila[v]) fail();
    return;
  }
  vis[v] = 1;
  mila[v] = color;
  for (auto i : g[v]) {
    int u = i.first;
    int w = i.second;
    if (w == 1) {
      dfs(u, 1 - color);
    } else {
      dfs(u, color);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) cin >> r[i];
  for (int i = (1); i <= (m); i++) {
    int x;
    cin >> x;
    for (int j = (1); j <= (x); j++) {
      int v;
      cin >> v;
      cont[v].push_back(i);
    }
  }
  for (int i = (1); i <= (n); i++) {
    if (r[i] == 0) {
      int u = cont[i][0];
      int v = cont[i][1];
      g[u].push_back({v, 1});
      g[v].push_back({u, 1});
    } else {
      int u = cont[i][0];
      int v = cont[i][1];
      g[u].push_back({v, 0});
      g[v].push_back({u, 0});
    }
  }
  for (int i = 1; i <= m; i++) {
    if (vis[i] == 0) {
      dfs(i, 0);
    }
  }
  cout << "YES";
  return 0;
}
