#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(7);
  cout << fixed;
  smain();
  return 0;
}
long long n, m;
long long r[300002], c[300002];
vector<long long> a[300002];
vector<long long> edges[300002], rev[300002];
vector<long long> order;
void add_edge(long long i, long long j) {
  edges[i ^ 1].push_back(j);
  rev[j].push_back(i ^ 1);
  edges[j ^ 1].push_back(i);
  rev[i].push_back(j ^ 1);
}
bool used[300002];
void dfs1(long long v) {
  used[v] = 1;
  for (auto j : edges[v])
    if (!used[j]) dfs1(j);
  order.push_back(v);
}
void dfs2(long long v, long long cur) {
  c[v] = cur;
  for (auto j : rev[v])
    if (c[j] == -1) dfs2(j, cur);
}
void smain() {
  for (; cin >> n >> m;) {
    for (long long i = 0; i < n; i++) cin >> r[i];
    for (long long i = 0; i < n; i++) a[i].clear();
    for (long long i = 0; i < 2 * m; i++) edges[i].clear(), rev[i].clear();
    for (long long i = 0; i < m; i++) {
      long long k, x;
      cin >> k;
      for (long long j = 0; j < k; j++) {
        cin >> x;
        a[x - 1].push_back(i);
      }
    }
    for (long long i = 0; i < n; i++) {
      long long x = 2 * a[i].front(), y = 2 * a[i].back();
      if (r[i]) {
        add_edge(x, y ^ 1);
        add_edge(x ^ 1, y);
      } else {
        add_edge(x ^ 1, y ^ 1);
        add_edge(x, y);
      }
    }
    memset(used, 0, 2 * m);
    order.clear();
    for (long long i = 0; i < 2 * m; i++)
      if (!used[i]) dfs1(i);
    memset(c, 255, sizeof(long long) * 2 * m);
    reverse(order.begin(), order.end());
    long long j = 0;
    for (auto i : order)
      if (c[i] == -1) dfs2(i, j++);
    bool ok = true;
    for (long long i = 0; i < 2 * m; i++)
      if (c[i] == c[i ^ 1]) ok = false;
    cout << (ok ? "YES" : "NO") << endl;
  }
}
