#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2E5 + 5;
bool truth[MAXN];
int nvar;
int neg(int x) { return MAXN - 1 - x; }
vector<int> g[MAXN];
int n, lw[MAXN], idx[MAXN], qidx, cmp[MAXN], qcmp;
void addor(int a, int b) {
  g[neg(a)].push_back(b);
  g[neg(b)].push_back(a);
}
stack<int> st;
void dfs(int u) {
  lw[u] = idx[u] = ++qidx;
  st.push(u);
  cmp[u] = -2;
  for (int v : g[u]) {
    if (!idx[v] || -cmp[v] == 2) {
      if (!idx[v]) dfs(v);
      lw[u] = min(lw[u], lw[v]);
    }
  }
  if (lw[u] == idx[u]) {
    int x, l = -1;
    do {
      x = st.top();
      st.pop();
      cmp[x] = qcmp;
      if (min(x, neg(x)) < nvar) l = x;
    } while (x != u);
    if (l != -1) truth[qcmp] = (cmp[neg(l)] < 0);
    qcmp++;
  }
}
void scc() {
  memset(idx, 0, sizeof(idx));
  qidx = 0;
  memset(cmp, -1, sizeof(cmp));
  qcmp = 0;
  for (int i = (0), ThxMK = (n); i < ThxMK; ++i)
    if (!idx[i]) dfs(i);
}
bool satisf(int _nvar) {
  nvar = _nvar;
  n = MAXN;
  scc();
  for (int i = (0), ThxMK = (nvar); i < ThxMK; ++i)
    if (cmp[i] == cmp[neg(i)]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n);
  for (int i = (0), ThxMK = (n); i < ThxMK; ++i) cin >> v[i];
  vector<vector<long long>> ores(n);
  for (int i = (0), ThxMK = (m); i < ThxMK; ++i) {
    long long x;
    cin >> x;
    while (x--) {
      long long y;
      cin >> y;
      y--;
      ores[y].push_back(i);
    }
  }
  for (int i = (0), ThxMK = (n); i < ThxMK; ++i) {
    if (v[i])
      addor(neg(ores[i][0]), ores[i][1]), addor(ores[i][0], neg(ores[i][1]));
    else
      addor(ores[i][0], ores[i][1]), addor(neg(ores[i][0]), neg(ores[i][1]));
  }
  cout << (satisf(m) ? "YES" : "NO") << '\n';
  return 0;
}
