#include <bits/stdc++.h>
using namespace std;
int n, m;
int r[100055];
int cmp[200055];
bool used[200055];
vector<int> g[200055], rg[200055], vs;
vector<int> light[200055];
inline void add_edge(int from, int to) {
  g[from].push_back(to);
  rg[to].push_back(from);
}
void dfs(int v) {
  used[v] = true;
  for (auto u : g[v]) {
    if (!used[u]) {
      dfs(u);
    }
  }
  vs.push_back(v);
}
void rdfs(int v, int k) {
  used[v] = true;
  cmp[v] = k;
  for (auto u : rg[v]) {
    if (!used[u]) {
      rdfs(u, k);
    }
  }
}
void scc() {
  for (int i = 0; i < m + m; i++) {
    if (!used[i]) {
      dfs(i);
    }
  }
  memset(used, false, sizeof(used));
  int k = 0;
  for (int i = m + m - 1; i >= 0; i--) {
    if (!used[vs[i]]) {
      rdfs(vs[i], k++);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &r[i]);
  }
  for (int j = 0; j < m; j++) {
    int x;
    scanf("%d", &x);
    vector<int> vec(x);
    for (int i = 0; i < x; i++) {
      scanf("%d", &vec[i]);
      vec[i]--;
      light[vec[i]].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    int x = light[i][0], y = light[i][1];
    if (r[i]) {
      add_edge(x, y);
      add_edge(y, x);
      add_edge(x + m, y + m);
      add_edge(y + m, x + m);
    } else {
      add_edge(x, y + m);
      add_edge(y, x + m);
      add_edge(x + m, y);
      add_edge(y + m, x);
    }
  }
  scc();
  for (int i = 0; i < m; i++) {
    if (cmp[i] == cmp[i + m]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
