#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 10;
vector<pair<int, int> > edge[Maxn];
int d[Maxn], c[Maxn];
int n, m;
vector<int> p[Maxn];
bool flag;
void DFS(int u, int dp) {
  int x, y, tmp;
  if (!flag) return;
  if (c[u] != -1) {
    if (c[u] != dp) flag = false;
    return;
  }
  c[u] = dp;
  int sz = (int)edge[u].size();
  for (int i = 0; i < sz; i++) {
    x = edge[u][i].first, y = edge[u][i].second;
    if (y)
      tmp = dp;
    else
      tmp = 1 - dp;
    DFS(x, tmp);
  }
}
int main() {
  int k, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    p[i].clear();
  }
  for (int i = 1; i <= m; i++) {
    cin >> k;
    for (int j = 1; j <= k; j++) {
      cin >> v;
      p[v].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    u = p[i][0], v = p[i][1];
    edge[u].push_back(make_pair(v, d[i]));
    edge[v].push_back(make_pair(u, d[i]));
  }
  memset(c, -1, sizeof(c));
  flag = true;
  for (int i = 1; i <= m; i++)
    if (c[i] == -1 && flag) DFS(i, 0);
  if (!flag)
    puts("NO");
  else
    puts("YES");
  return 0;
}
