#include <bits/stdc++.h>
using namespace std;
const int maxn = 200086;
const int inf = 2.1e9;
const long long Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1);
int n, m;
int num[maxn], f[maxn], rec[maxn];
int getf(int x) {
  if (f[x] == x) {
    return x;
  }
  return f[x] = getf(f[x]);
}
void Merge(int x, int y) {
  int t1 = getf(x);
  int t2 = getf(y);
  if (t1 != t2) {
    f[t1] = f[t2];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  for (int i = 1; i <= m; i++) {
    f[i] = i;
    f[i + m] = i + m;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d", &x);
    for (int j = 1; j <= x; j++) {
      scanf("%d", &y);
      if (rec[y]) {
        if (num[y] == 0) {
          Merge(i, rec[y] + m);
          Merge(i + m, rec[y]);
        } else {
          Merge(i, rec[y]);
          Merge(i + m, rec[y] + m);
        }
      } else {
        rec[y] = i;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (getf(i) == getf(i + m)) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
