#include <bits/stdc++.h>
using namespace std;
const int N = 1000002;
vector<int> swit[100005];
int head[N], nxt[N << 1], to[N << 1], no = 0;
int dfsnum[N], dfsn = 0, low[N];
int ccnum[N], cnum = 0;
bool instack[N];
void link(int a, int b) {
  nxt[no] = head[a];
  to[no] = b;
  head[a] = no++;
}
void addxor(int a, int b) {
  a <<= 1;
  b <<= 1;
  link(a, b ^ 1);
  link(b, a ^ 1);
  link(a ^ 1, b);
  link(b ^ 1, a);
}
void addxnor(int a, int b) {
  a <<= 1;
  b <<= 1;
  link(a, b);
  link(b, a);
  link(a ^ 1, b ^ 1);
  link(b ^ 1, a ^ 1);
}
stack<int> scc;
void dfs(int idx) {
  dfsnum[idx] = low[idx] = dfsn++;
  scc.push(idx);
  instack[idx] = 1;
  for (int i = head[idx]; ~i; i = nxt[i]) {
    int nx = to[i];
    if (dfsnum[nx] == -1) {
      dfs(nx);
    }
    if (instack[nx]) low[idx] = min(low[idx], low[nx]);
  }
  if (low[idx] == dfsnum[idx]) {
    while (scc.top() != idx) {
      int v = scc.top();
      scc.pop();
      instack[v] = 0;
      ccnum[v] = cnum;
    }
    scc.pop();
    instack[idx] = 0;
    ccnum[idx] = cnum++;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  memset(head, -1, sizeof head);
  for (int i = 0; i < n; i++) cin >> dfsnum[i];
  int x, v;
  for (int i = 0; i < m; i++) {
    cin >> x;
    while (x--) {
      cin >> v;
      swit[v - 1].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (dfsnum[i] == 0) {
      addxor(swit[i][0], swit[i][1]);
    } else {
      addxnor(swit[i][0], swit[i][1]);
    }
  }
  swap(n, m);
  memset(dfsnum, -1, sizeof dfsnum);
  memset(ccnum, -1, sizeof ccnum);
  n *= 2;
  for (int i = 0; i < n; i += 2) {
    if (dfsnum[i] == -1) dfs(i);
  }
  for (int i = 0; i < n; i += 2) {
    if (ccnum[i] == ccnum[i ^ 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
