#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, sum, cnt, ans, a[100005], c[100005];
pair<int, int> edges[100005];
vector<pair<int, int> > v[100005];
void dfs(int x, int paint) {
  if (c[x]) {
    if (c[x] != paint) {
      printf("NO\n");
      exit(0);
    }
    return;
  }
  c[x] = paint;
  for (auto y : v[x]) {
    if (y.second)
      dfs(y.first, paint);
    else
      dfs(y.first, 3 - paint);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    while (x--) {
      scanf("%d", &y);
      if (edges[y].first)
        edges[y].second = i;
      else
        edges[y].first = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    v[edges[i].first].push_back({edges[i].second, a[i]});
    v[edges[i].second].push_back({edges[i].first, a[i]});
  }
  for (int i = 1; i <= m; i++) {
    if (!c[i]) {
      dfs(i, 1);
    }
  }
  printf("YES\n");
  return 0;
}
