#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
vector<int> g[N], g1[N];
stack<int> s;
int n, m;
int dfn[N], be[N], low[N], ln, vis[N], gcnt;
void tarjan(int x) {
  dfn[x] = low[x] = ++gcnt;
  vis[x] = 1;
  s.push(x);
  for (int i = 0; i < g[x].size(); i++) {
    int to = g[x][i];
    if (!dfn[to]) {
      tarjan(to);
      low[x] = min(low[x], low[to]);
    } else if (vis[to]) {
      low[x] = min(low[x], dfn[to]);
    }
  }
  int cur;
  if (dfn[x] == low[x]) {
    ln++;
    do {
      cur = s.top();
      s.pop();
      vis[cur] = 0;
      be[cur] = ln;
    } while (cur != x);
  }
}
int a[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int t = 1; t <= m; t++) {
    int x;
    scanf("%d", &x);
    for (int j = 1; j <= x; j++) {
      int y;
      scanf("%d", &y);
      g1[y].push_back(t);
    }
  }
  for (int i = 1; i <= n; i++) {
    int x = g1[i][0], y = g1[i][1];
    if (a[i] == 1) {
      g[x].push_back(y);
      g[y + m].push_back(x + m);
      g[y].push_back(x);
      g[x + m].push_back(y + m);
    } else {
      g[x].push_back(y + m);
      g[x + m].push_back(y);
      g[y].push_back(x + m);
      g[y + m].push_back(x);
    }
  }
  for (int i = 1; i <= (m << 1); i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= m; i++)
    if (be[i] == be[i + m]) {
      printf("NO\n");
      return 0;
    }
  printf("YES\n");
}
