#include <bits/stdc++.h>
using namespace std;
const int64_t DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9 + 7;
const int N = 1e5 + 5;
int vis[2 * N], comp[2 * N];
vector<int> g[2 * N], rg[2 * N], order;
void implies(int p, int q) {
  g[p].emplace_back(q);
  rg[q].emplace_back(p);
}
void Or(int p, int q) {
  implies(p ^ 1, q);
  implies(q ^ 1, p);
}
void Xor(int p, int q) {
  Or(p, q);
  Or(p ^ 1, q ^ 1);
}
void Biconditional(int p, int q) { Xor(p, q ^ 1); }
void dfs1(int v) {
  vis[v] = 1;
  for (auto& x : g[v])
    if (!vis[x]) dfs1(x);
  order.emplace_back(v);
}
void dfs2(int v, int k) {
  comp[v] = k;
  for (auto& x : rg[v])
    if (comp[x] == -1) dfs2(x, k);
}
bool is_sat(int n) {
  memset(comp, -1, sizeof(comp));
  order.reserve(2 * n);
  for (int i = 0; i < 2 * n; i++)
    if (!vis[i]) dfs1(i);
  reverse(order.begin(), order.end());
  int sccnt = 0;
  for (auto& v : order)
    if (comp[v] == -1) dfs2(v, sccnt++);
  for (int i = 0; i < n; i++) {
    if (comp[i << 1] == comp[i << 1 | 1]) return false;
  }
  return true;
}
int32_t main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int i, n, m;
  cin >> n >> m;
  vector<int> unlocked(n);
  for (i = 0; i < n; i++) cin >> unlocked[i];
  vector<vector<int>> switches(n);
  for (i = 0; i < m; i++) {
    int t;
    cin >> t;
    while (t--) {
      int r;
      cin >> r;
      switches[--r].emplace_back(i);
    }
  }
  for (i = 0; i < n; i++) {
    int u = switches[i][0];
    int v = switches[i][1];
    if (unlocked[i])
      Biconditional(u << 1, v << 1);
    else
      Xor(u << 1, v << 1);
  }
  cout << (is_sat(m) ? "YES" : "NO") << '\n';
}
