#include <bits/stdc++.h>
using namespace std;
int r[100001], color[100001];
vector<pair<int, int> > g[100001];
vector<int> v[100001];
bool dfs(int u, int c) {
  color[u] = c;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first, w = g[u][i].second;
    if (w == 1) {
      if (color[v]) {
        if (color[v] == c) continue;
        return 0;
      }
      if (!dfs(v, c)) return 0;
    } else {
      if (color[v]) {
        if (color[v] != c) continue;
        return 0;
      }
      if (!dfs(v, 3 - c)) return 0;
    }
  }
  return 1;
}
int main() {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d", &x);
    for (int j = 1; j <= x; j++) {
      scanf("%d", &y);
      v[y].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    g[v[i][0]].push_back(pair<int, int>(v[i][1], r[i]));
    g[v[i][1]].push_back(pair<int, int>(v[i][0], r[i]));
  }
  bool ok = 1;
  for (int i = 1; i <= m; i++)
    if (!color[i]) ok &= dfs(i, 1);
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
}
