#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 520;
int n, m, key[N][2], cnt[N], f[N], now[N];
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ '0');
    c = getchar();
  }
  return f * x;
}
inline int Find(int x) {
  if (x == f[x]) return x;
  int res = Find(f[x]);
  f[x] = res;
  return res;
}
inline void add(int x, int y) {
  int X = Find(x), Y = Find(y);
  if (X == Y) return;
  f[X] = Y;
  return;
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) now[i] = read();
  for (int i = 1; i <= m; i++) {
    f[i] = i, f[i + m] = i + m;
    int x = read();
    for (int j = 1; j <= x; j++) {
      int y = read();
      key[y][cnt[y]] = i;
      cnt[y]++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (now[i] == 1)
      add(key[i][0], key[i][1]), add(key[i][0] + m, key[i][1] + m);
    else
      add(key[i][0], key[i][1] + m), add(key[i][0] + m, key[i][1]);
  for (int i = 1; i <= m; i++)
    if (Find(i) == Find(i + m)) {
      puts("NO");
      return 0;
    }
  puts("YES");
  return 0;
}
