#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int n, m;
int visited[300005], belongTo[300005], scc;
pair<int, pair<int, int> > stat[300005];
vector<vector<int> > ar;
stack<int> st;
void dfs(int node, bool x) {
  visited[node] = 1;
  for (auto nx : ar[node]) {
    if (!visited[nx]) dfs(nx, x);
  }
  if (x)
    belongTo[node] = scc;
  else
    st.push(node);
}
int main() {
  scanf("%d%d", &n, &m);
  ar.assign(200001 + 1, vector<int>());
  for (int i = 1; i <= n; ++i) scanf("%d", &stat[i].first);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d", &x);
    while (x--) {
      scanf("%d", &y);
      if (stat[y].first) {
        if (stat[y].second.first) {
          int x = stat[y].second.first;
          ar[x].push_back(i);
          ar[i].push_back(x);
          ar[i + 100000].push_back(x + 100000);
          ar[x + 100000].push_back(i + 100000);
        } else
          stat[y].second.first = i;
      } else {
        if (stat[y].second.first) {
          int x = stat[y].second.first;
          ar[i].push_back(x + 100000);
          ar[x + 100000].push_back(i);
          ar[i + 100000].push_back(x);
          ar[x].push_back(i + 100000);
        } else
          stat[y].second.first = i;
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (!visited[i]) dfs(i, 0);
  }
  memset(visited, 0, sizeof visited);
  while (st.size()) {
    if (!visited[st.top()]) ++scc, dfs(st.top(), 1);
    st.pop();
  }
  for (int i = 1; i <= m; ++i) {
    if (belongTo[i] == belongTo[i + 100000]) return printf("NO"), 0;
  }
  printf("YES");
  return 0;
}
