#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int state[n];
  for (int i = 0; i < n; i++) {
    cin >> state[i];
  }
  vector<int> v[n];
  for (int i = 0; i < m; i++) {
    int sz, y;
    cin >> sz;
    for (int j = 0; j < sz; j++) {
      cin >> y;
      v[y - 1].push_back(i);
    }
  }
  map<int, pair<int, int> > mp;
  vector<pair<int, int> > g[m];
  for (int i = 0; i < n; i++) {
    g[v[i][0]].push_back({v[i][1], i});
    g[v[i][1]].push_back({v[i][0], i});
  }
  vector<int> color(m, 0), vis(n, 0);
  priority_queue<int> pq;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) pq.push(v[i][0]);
    while (!pq.empty()) {
      int src = pq.top();
      pq.pop();
      for (int i = 0; i < g[src].size(); i++) {
        int des = g[src][i].first, room = g[src][i].second;
        if (!vis[room]) {
          vis[room] = 1;
          if (state[room] == 1) {
            color[des] = color[src];
          } else {
            color[des] = 1 - color[src];
          }
          pq.push(des);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (state[i] == 1) {
      if (color[v[i][0]] != color[v[i][1]]) {
        cout << "NO";
        return 0;
      }
    } else {
      if (color[v[i][0]] == color[v[i][1]]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
