#include <bits/stdc++.h>
std::vector<int> a[200005];
int x[100005], y[100005], f[100005], n, m, g[200005], flag;
void add(int x, int y) { a[x].push_back(y); }
int dfs(int v) {
  int x = v > m ? -m : m;
  for (int i = 0; i < a[v].size(); i++) {
    int u = a[v][i];
    int y = u > m ? -m : m;
    if (g[u] == 0 || g[u + y] == 1) {
      flag = 1;
      break;
    } else if (g[u] == -1 && g[u + y] == -1) {
      g[u] = 1;
      g[u + y] = 0;
      dfs(u);
      if (flag) break;
    }
  }
  if (flag) {
    g[v] = g[v + x] = -1;
    return 0;
  } else
    return 1;
}
int twosat() {
  for (int i = 1; i <= m * 2; i++) g[i] = -1;
  for (int i = 1; i <= m; i++)
    if (g[i] == -1) {
      g[i] = 1;
      g[i + m] = 0;
      flag = 0;
      if (dfs(i)) continue;
      g[i] = 0, g[i + m] = 1;
      flag = 0;
      if (dfs(i + m)) continue;
      return 0;
    }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= m; i++) {
    int s, p;
    scanf("%d", &s);
    for (int j = 1; j <= s; j++) {
      scanf("%d", &p);
      if (!x[p])
        x[p] = i;
      else
        y[p] = i;
    }
  }
  for (int i = 1; i <= n; i++)
    if (f[i] == 1)
      add(x[i], y[i]), add(x[i] + m, y[i] + m), add(y[i], x[i]),
          add(y[i] + m, x[i] + m);
    else
      add(x[i], y[i] + m), add(x[i] + m, y[i]), add(y[i], x[i] + m),
          add(y[i] + m, x[i]);
  twosat() ? puts("YES") : puts("NO");
  return 0;
}
