#include <bits/stdc++.h>
using namespace std;
long long r[100005], parity[100005], f;
vector<long long> a[100005];
vector<long long> s[100005];
void set_p(long long sw, long long p) {
  parity[sw] = p;
  for (auto rm : a[sw]) {
    for (auto nsw : s[rm]) {
      if (sw != nsw) {
        if (parity[nsw] == -1)
          set_p(nsw, !(r[rm] ^ p));
        else if (parity[nsw] != (!(r[rm] ^ p))) {
          f = 1;
          return;
        }
      }
    }
  }
}
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i++) cin >> r[i];
  for (long long i = 1; i < m + 1; i++) {
    long long x;
    cin >> x;
    for (long long j = 0; j < x; j++) {
      long long u;
      cin >> u;
      a[i].push_back(u);
      s[u].push_back(i);
    }
  }
  long long ans = 1;
  for (long long it = 0; it < 2; it++) {
    for (long long i = 1; i < m + 1; i++) parity[i] = -1;
    f = 0;
    for (long long i = 1; i < m + 1; i++) {
      if (parity[i] == -1) set_p(i, it);
    }
    ans = ans & f;
  }
  if (ans)
    cout << "NO";
  else
    cout << "YES";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
