#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
vector<long long> g[2 * N], gt[2 * N];
long long n, m;
long long inline knot(long long a) { return (a ^ 1); }
vector<bool> used;
vector<long long> order, comp;
vector<bool> assignment;
void dfs1(long long v) {
  used[v] = true;
  for (long long u : g[v]) {
    if (!used[u]) dfs1(u);
  }
  order.push_back(v);
}
void dfs2(long long v, long long cl) {
  comp[v] = cl;
  for (long long u : gt[v]) {
    if (comp[u] == -1) dfs2(u, cl);
  }
}
bool solve_2SAT() {
  long long n = 2 * m;
  used.assign(n, false);
  for (long long i = 0; i < n; ++i) {
    if (!used[i]) dfs1(i);
  }
  comp.assign(n, -1);
  for (long long i = 0, j = 0; i < n; ++i) {
    long long v = order[n - i - 1];
    if (comp[v] == -1) dfs2(v, j++);
  }
  assignment.assign(n / 2, false);
  for (long long i = 0; i < n; i += 2) {
    if (comp[i] == comp[i + 1]) return false;
    assignment[i / 2] = comp[i] > comp[i + 1];
  }
  return true;
}
void solve() {
  cin >> n >> m;
  vector<long long> condition(n + 1, -1);
  vector<vector<long long> > a(n + 1);
  for (long long i = 1; i < n + 1; ++i) {
    cin >> condition[i];
  }
  for (long long i = 0; i < m; ++i) {
    long long x;
    cin >> x;
    for (long long j = 0; j < x; ++j) {
      long long y;
      cin >> y;
      a[y].push_back(i * 2);
    }
  }
  for (long long i = 1; i < n + 1; ++i) {
    if (condition[i] == 0) {
      g[a[i][0]].push_back(a[i][1] ^ 1);
      g[a[i][1] ^ 1].push_back(a[i][0]);
      g[a[i][1]].push_back(a[i][0] ^ 1);
      g[a[i][0] ^ 1].push_back(a[i][1]);
      gt[a[i][0]].push_back(a[i][1] ^ 1);
      gt[a[i][1] ^ 1].push_back(a[i][0]);
      gt[a[i][1]].push_back(a[i][0] ^ 1);
      gt[a[i][0] ^ 1].push_back(a[i][1]);
    } else {
      g[a[i][0]].push_back(a[i][1]);
      g[a[i][1]].push_back(a[i][0]);
      g[a[i][0] ^ 1].push_back(a[i][1] ^ 1);
      g[a[i][1] ^ 1].push_back(a[i][0] ^ 1);
      gt[a[i][0]].push_back(a[i][1]);
      gt[a[i][1]].push_back(a[i][0]);
      gt[a[i][0] ^ 1].push_back(a[i][1] ^ 1);
      gt[a[i][1] ^ 1].push_back(a[i][0] ^ 1);
    }
  }
  if (solve_2SAT()) {
    cout << "YES";
  } else
    cout << "NO";
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
