#include <bits/stdc++.h>
using namespace std;
struct yee {
  bool lock;
  vector<int> sw;
};
yee y[200004];
int p;
bool visited[400008];
int scc[400008];
vector<int> finish;
vector<int> sat[400008];
void XO(int a, int b) {
  sat[2 * a + 1].push_back(2 * b);
  sat[2 * b + 1].push_back(2 * a);
  sat[2 * a].push_back(2 * b + 1);
  sat[2 * b].push_back(2 * a + 1);
}
void NX(int a, int b) {
  sat[2 * a + 1].push_back(2 * b + 1);
  sat[2 * b].push_back(2 * a);
  sat[2 * a].push_back(2 * b);
  sat[2 * b + 1].push_back(2 * a + 1);
}
void dfs1(int i) {
  visited[i] = true;
  for (int x : sat[i])
    if (!visited[x]) dfs1(x);
  finish.push_back(i);
}
void dfs2(int i) {
  scc[i] = p;
  visited[i] = true;
  for (int x : sat[i])
    if (!visited[x]) dfs2(x);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    if (tmp == 0) y[i].lock = true;
  }
  for (int i = 0; i < m; i++) {
    int num;
    scanf("%d", &num);
    while (num--) {
      int tmp;
      scanf("%d", &tmp);
      y[tmp - 1].sw.push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (y[i].lock)
      XO(y[i].sw[0], y[i].sw[1]);
    else
      NX(y[i].sw[0], y[i].sw[1]);
  }
  for (int i = 0; i < m * 2; i++)
    if (!visited[i]) dfs1(i);
  for (int i = 0; i < m * 2; i++) visited[i] = false;
  for (auto it = finish.rbegin(); it != finish.rend(); it++) {
    if (!visited[*it]) {
      dfs2(*it);
      p++;
    }
  }
  bool ans = true;
  for (int i = 0; i < m; i++) {
    if (scc[i * 2] == scc[i * 2 + 1]) {
      ans = false;
      break;
    }
  }
  printf(ans ? "YES\n" : "NO\n");
}
