#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<vector<long long> > raz(100010);
vector<vector<long long> > od(100010);
vector<long long> u(100010, 0);
vector<long long> cv(100010, 0);
long long fl = 0;
void dfs(long long v, long long &fl) {
  if (cv[v] == 0) cv[v] = 1;
  u[v] = 1;
  long long r1 = od[v].size();
  for (long long i1 = 0; i1 < r1; i1++) {
    if (cv[od[v][i1]] + cv[v] == 3) {
      fl = 1;
    } else if (cv[od[v][i1]] == 0 && u[od[v][i1]] == 0) {
      cv[od[v][i1]] = cv[v];
      dfs(od[v][i1], fl);
    }
  }
  long long r2 = raz[v].size();
  for (long long i1 = 0; i1 < r2; i1++) {
    if (cv[raz[v][i1]] == cv[v]) {
      fl = 1;
    } else if (cv[raz[v][i1]] == 0 && u[raz[v][i1]] == 0) {
      cv[raz[v][i1]] = 3 - cv[v];
      dfs(raz[v][i1], fl);
    }
  }
}
int main() {
  cin >> n >> m;
  vector<long long> a(n + 1);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  vector<vector<long long> > l(n + 1);
  for (long long i = 1; i <= m; i++) {
    long long x;
    cin >> x;
    for (long long j = 1; j <= x; j++) {
      long long ch;
      cin >> ch;
      l[ch].push_back(i);
    }
  }
  for (long long i = 1; i <= n; i++) {
    long long t1 = l[i][0];
    long long t2 = l[i][1];
    if (a[i] == 0) {
      raz[t1].push_back(t2);
      raz[t2].push_back(t1);
    } else if (a[i] == 1) {
      od[t1].push_back(t2);
      od[t2].push_back(t1);
    }
  }
  for (long long i = 1; i <= m; i++) {
    if (u[i] == 0) {
      dfs(i, fl);
    }
  }
  if (fl == 1)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
