#include <bits/stdc++.h>
using namespace std;
struct node {
  int stat;
  int doosra;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int stat[n + 1];
  for (int i = 1; i <= n; i++) cin >> stat[i];
  vector<int> temp[n + 1];
  for (int i = 1; i <= m; i++) {
    int var, k;
    cin >> var;
    for (int j = 1; j <= var; j++) {
      cin >> k;
      temp[k].push_back(i);
    }
  }
  vector<node> edges[m + 1];
  for (int i = 1; i <= n; i++) {
    int first = temp[i].at(0);
    int second = temp[i].at(1);
    edges[first].push_back(node{stat[i], second});
    edges[second].push_back(node{stat[i], first});
  }
  queue<int> q;
  bool visited[m + 1];
  int toggle[m + 1];
  for (int i = 1; i <= m; i++) {
    toggle[i] = -1;
    visited[i] = false;
  }
  for (int i = 1; i <= m; i++) {
    if (visited[i]) continue;
    toggle[i] = 0;
    q.push(i);
    while (!q.empty()) {
      int var = q.front();
      q.pop();
      if (visited[var]) continue;
      visited[var] = true;
      for (auto idx : edges[var]) {
        if (idx.stat == 0) {
          toggle[idx.doosra] = 1 - toggle[var];
          q.push(idx.doosra);
        }
        if (idx.stat == 1) {
          toggle[idx.doosra] = toggle[var];
          q.push(idx.doosra);
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < edges[i].size(); j++) {
      if (edges[i].at(j).stat == 0 &&
              toggle[i] == toggle[edges[i].at(j).doosra] ||
          edges[i].at(j).stat == 1 &&
              toggle[i] != toggle[edges[i].at(j).doosra]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
