#include <bits/stdc++.h>
using namespace std;
class Scc {
  vector<int> vs;
  vector<bool> used;
  vector<vector<int>> E, G;

 public:
  vector<int> cmp;
  int n;
  Scc(int N) {
    n = N;
    E.resize(n);
    G.resize(n);
    cmp.resize(n);
  }

 private:
  void dfs(int v) {
    used[v] = true;
    for (auto u : E[v]) {
      if (!used[u]) dfs(u);
    }
    vs.push_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (auto u : G[v]) {
      if (!used[u]) rdfs(u, k);
    }
  }

 public:
  void add_edge(int a, int b) {
    E[a].push_back(b);
    G[b].push_back(a);
  }
  int scc() {
    used.assign(n, 0);
    vs.clear();
    for (int v = 0; v < n; v++) {
      if (!used[v]) dfs(v);
    }
    used.assign(n, 0);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }
};
int r[100000];
vector<int> v[100000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); i++) scanf("%d", &r[i]);
  for (int i = 0; i < (m); i++) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < (x); j++) {
      int a;
      scanf("%d", &a);
      a--;
      v[a].push_back(i);
    }
  }
  Scc scc(2 * m);
  for (int i = 0; i < (n); i++) {
    if (r[i] == 0) {
      scc.add_edge(v[i][0], v[i][1] + m);
      scc.add_edge(v[i][1], v[i][0] + m);
      scc.add_edge(v[i][1] + m, v[i][0]);
      scc.add_edge(v[i][0] + m, v[i][1]);
    } else {
      scc.add_edge(v[i][0] + m, v[i][1] + m);
      scc.add_edge(v[i][1] + m, v[i][0] + m);
      scc.add_edge(v[i][0], v[i][1]);
      scc.add_edge(v[i][1], v[i][0]);
    }
  }
  scc.scc();
  for (int i = 0; i < (m); i++) {
    if (scc.cmp[i] == scc.cmp[i + m]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
}
