#include <bits/stdc++.h>
using namespace std;
namespace SCC {
const int MX = (int)1e6 + 5;
int n, id[MX], idn, gp_id[MX], gn;
bool vis[MX];
vector<int> con[MX], rcon[MX], gp[MX], gcon[MX];
void init(int sz) {
  n = sz, idn = gn = 0;
  for (int i = 0; i <= n; i++) {
    con[i].clear(), rcon[i].clear(), gp[i].clear(), gcon[i].clear();
    vis[i] = false;
  }
}
inline void add_edge(int u, int v) {
  con[u].push_back(v), rcon[v].push_back(u);
}
void dfs(int u) {
  vis[u] = true;
  for (int v : con[u])
    if (!vis[v]) dfs(v);
  id[idn++] = u;
}
void rdfs(int u) {
  vis[u] = true;
  gp_id[u] = gn;
  gp[gn].push_back(u);
  for (int v : rcon[u])
    if (!vis[v]) rdfs(v);
}
void SCC(int Group = 0) {
  for (int i = 0; i <= n; i++)
    if (!vis[i]) dfs(i);
  memset(vis, 0, sizeof(bool) * (n + 1));
  for (int i = idn - 1; i >= 0; i--)
    if (!vis[id[i]]) gn++, rdfs(id[i]);
  if (Group) {
    for (int i = 0; i <= n; i++)
      for (int v : con[i])
        if (gp_id[i] != gp_id[v]) gcon[gp_id[i]].push_back(gp_id[v]);
    for (int i = 1; i <= gn; i++) {
      sort(gcon[i].begin(), gcon[i].end());
      gcon[i].erase(unique(gcon[i].begin(), gcon[i].end()), gcon[i].end());
    }
  }
}
}  // namespace SCC
namespace TWO_SAT {
const int MX = (int)1e5 + 5;
int val[2 * MX];
inline int Not(int u) {
  if (u < MX) return u + MX;
  return u - MX;
}
inline void add_edge(int u, int v) {
  SCC::add_edge(u, v), SCC::add_edge(Not(v), Not(u));
}
inline void add_true(int u) { add_edge(Not(u), u); }
inline void add_false(int u) { add_edge(u, Not(u)); }
inline void add_or(int u, int v) { add_edge(Not(u), v); }
inline void add_and(int u, int v) { add_true(u), add_true(v); }
inline void add_equal(int u, int v) { add_edge(u, v), add_edge(v, u); }
inline void add_diff(int u, int v) { add_edge(u, Not(v)), add_edge(Not(u), v); }
bool TWO_SAT() {
  SCC::SCC();
  memset(val, 0xff, sizeof val);
  for (int i = SCC::gn - 1; i >= 0; i--) {
    for (int v : SCC::gp[i]) {
      if (SCC::gp_id[v] == SCC::gp_id[Not(v)]) return false;
      if (val[Not(v)] == -1)
        val[v] = 1;
      else
        val[v] = 0;
    }
  }
  return true;
}
void init() { SCC::init(2 * MX); }
}  // namespace TWO_SAT
int a[150000];
vector<int> con[150000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int k;
    cin >> k;
    while (k--) {
      int u;
      cin >> u;
      con[u].push_back(i);
    }
  }
  TWO_SAT::init();
  for (int i = 1; i <= n; i++) {
    if (!a[i])
      TWO_SAT::add_diff(con[i][0], con[i][1]);
    else
      TWO_SAT::add_equal(con[i][0], con[i][1]);
  }
  if (TWO_SAT::TWO_SAT())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
