#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> cur[N];
vector<int> g[N];
int n, m, r[N], x, a, comp[N], comp_cnt = 0;
int dfs_low[N], dfs_num[N], dfs_cnt = 0;
bool vis[N];
stack<int> st;
inline int Not(int u) {
  if (u >= m) return u - m;
  return u + m;
}
inline void add(int u, int v) {
  g[Not(u)].push_back(v);
  g[Not(v)].push_back(u);
}
int tmp = 0;
void DFS(int node) {
  dfs_low[node] = dfs_num[node] = ++dfs_cnt;
  vis[node] = true;
  st.push(node);
  for (int i = 0; i < (int)g[node].size(); i++) {
    if (dfs_num[g[node][i]] == 0) DFS(g[node][i]);
    if (vis[g[node][i]])
      dfs_low[node] = min(dfs_low[node], dfs_low[g[node][i]]);
  }
  if (dfs_low[node] == dfs_num[node]) {
    while (true) {
      tmp = st.top();
      st.pop();
      comp[tmp] = comp_cnt;
      vis[tmp] = false;
      if (tmp == node) break;
    }
    comp_cnt++;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d", &x);
    for (int j = 0; j < x; j++) {
      scanf("%d", &a);
      cur[a].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (r[i] == 0) {
      add(cur[i][0], cur[i][1]);
      add(Not(cur[i][0]), Not(cur[i][1]));
    } else {
      add(cur[i][0], Not(cur[i][1]));
      add(Not(cur[i][0]), cur[i][1]);
    }
  }
  for (int i = 0; i < (m << 1); i++) {
    if (dfs_num[i] == 0) DFS(i);
  }
  for (int i = 0; i < (m << 1); i++) {
    if (comp[i] == comp[Not(i)]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
