#include <bits/stdc++.h>
using namespace std;
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
const int N = 2e5 + 5;
vector<int> adj[N];
bool vis[N];
vector<int> temp;
bool dfs(int u) {
  vis[u] = true;
  temp.push_back(u);
  for (auto v : adj[u]) {
    if (vis[v] == false && vis[v ^ 1] == true) {
      return false;
    } else if (vis[v] == false) {
      if (dfs(v) == false) {
        return false;
      }
    }
  }
  return true;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> r(n);
  for (int i = 0; i < n; ++i) cin >> r[i];
  vector<int> e[n];
  int u, v;
  for (int i = 0; i < m; ++i) {
    cin >> u;
    while (u--) {
      cin >> v;
      --v;
      e[v].push_back(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    u = e[i][0];
    v = e[i][1];
    v *= 2;
    u *= 2;
    if (r[i]) {
      adj[u].push_back(v);
      adj[v].push_back(u);
      adj[v ^ 1].push_back(u ^ 1);
      adj[u ^ 1].push_back(v ^ 1);
    } else {
      adj[u].push_back(v ^ 1);
      adj[v].push_back(u ^ 1);
      adj[v ^ 1].push_back(u);
      adj[u ^ 1].push_back(v);
    }
  }
  for (int i = 0; i < m; ++i) {
    u = i * 2;
    if (vis[u] == true || vis[u ^ 1] == true) continue;
    temp.clear();
    if (dfs(u) == false) {
      for (auto v : temp) vis[v] = false;
      if (dfs(u ^ 1) == false) {
        cout << "NO";
        return;
      }
    }
  }
  cout << "YES";
  return;
}
int main() {
  boost();
  int tc = 1;
  while (tc--) solve();
  return 0;
}
