#include <bits/stdc++.h>
using namespace std;
struct Scc {
  int n, nScc, vst[200005], bln[200005];
  vector<int> E[200005], rE[200005], vec;
  void init(int _n) {
    n = _n;
    for (int i = 0; i < 200005; i++) E[i].clear(), rE[i].clear();
  }
  void addEdge(int u, int v) {
    E[u].push_back(v);
    rE[v].push_back(u);
  }
  void DFS(int u) {
    vst[u] = 1;
    for (auto v : E[u])
      if (!vst[v]) DFS(v);
    vec.push_back(u);
  }
  void rDFS(int u) {
    vst[u] = 1;
    bln[u] = nScc;
    for (auto v : rE[u])
      if (!vst[v]) rDFS(v);
  }
  void solve() {
    nScc = 0;
    vec.clear();
    memset(vst, 0, sizeof(vst));
    for (int i = 0; i < n; i++)
      if (!vst[i]) DFS(i);
    reverse(vec.begin(), vec.end());
    memset(vst, 0, sizeof(vst));
    for (auto v : vec)
      if (!vst[v]) {
        rDFS(v);
        nScc++;
      }
  }
} scc;
int n, m;
bool status[200005];
vector<vector<int>> switchs, ctrl;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> status[i];
  switchs.resize(n);
  scc.init(m * 2);
  ctrl.resize(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    ctrl[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> ctrl[i][j];
      switchs[ctrl[i][j] - 1].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (status[i]) {
      scc.addEdge(switchs[i][0] + m, switchs[i][1] + m);
      scc.addEdge(switchs[i][1] + m, switchs[i][0] + m);
      scc.addEdge(switchs[i][0], switchs[i][1]);
      scc.addEdge(switchs[i][1], switchs[i][0]);
    } else {
      scc.addEdge(switchs[i][0], m + switchs[i][1]);
      scc.addEdge(switchs[i][1], m + switchs[i][0]);
      scc.addEdge(m + switchs[i][0], switchs[i][1]);
      scc.addEdge(m + switchs[i][1], switchs[i][0]);
    }
  }
  scc.solve();
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    if (scc.bln[i] > scc.bln[i + m]) {
      ans.push_back(i);
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    for (auto j : ctrl[ans[i]]) {
      status[j - 1] ^= 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!status[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
