#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
vector<int> toggle[MAXN];
vector<int> susedi[2 * MAXN];
int states[MAXN];
int used1[2 * MAXN], used2[2 * MAXN];
stack<int> order;
void dfs1(int v) {
  used1[v] = true;
  for (int i = 0; i < susedi[v].size(); i++) {
    if (!used1[susedi[v][i]]) {
      dfs1(susedi[v][i]);
    }
  }
  order.push(v);
}
int br;
void dfs2(int v) {
  if (used2[v]) return;
  used2[v] = br;
  for (int i = 0; i < susedi[v].size(); i++) {
    if (!used2[susedi[v][i]]) {
      dfs2(susedi[v][i]);
    }
  }
}
int parent[MAXN];
int find(int x) {
  if (parent[x] == x) {
    return x;
  }
  parent[x] = find(parent[x]);
  return parent[x];
}
void union_find(int a, int b) {
  int c = find(a);
  int d = find(b);
  parent[c] = d;
}
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> states[i];
  }
  for (int i = 0; i < m; i++) {
    int sz, lamp;
    cin >> sz;
    for (int j = 0; j < sz; j++) {
      cin >> lamp;
      toggle[lamp].push_back(i);
    }
    parent[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (states[i] == 1) union_find(toggle[i][0], toggle[i][1]);
  }
  int last = -1;
  for (int i = 1; i <= n; i++) {
    if (states[i] == 0) {
      if (find(toggle[i][0]) == find(toggle[i][1])) {
        cout << "NO\n";
        return 0;
      }
      last = find(toggle[i][0]);
      susedi[MAXN + find(toggle[i][0])].push_back(find(toggle[i][1]));
      susedi[MAXN + find(toggle[i][1])].push_back(find(toggle[i][0]));
      susedi[find(toggle[i][0])].push_back(MAXN + find(toggle[i][1]));
      susedi[find(toggle[i][1])].push_back(MAXN + find(toggle[i][0]));
    }
  }
  for (int i = 0; i < m; i++) {
    if (!used1[i]) {
      dfs1(i);
    }
  }
  br = 1;
  while (!order.empty()) {
    dfs2(order.top());
    order.pop();
    br++;
  }
  for (int i = 1; i <= n; i++) {
    if (states[i] == 0) {
      if (used2[find(toggle[i][0])] == used2[find(toggle[i][0]) + MAXN]) {
        cout << "NO\n";
        return 0;
      }
      if (used2[find(toggle[i][1])] == used2[find(toggle[i][1]) + MAXN]) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
