#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > room_to_switches;
vector<vector<pair<long long, long long> > > neighbors;
vector<long long> target;
void dfs(long long s, long long color, vector<long long>& colors) {
  if (colors[s] != -1) {
    if (color != colors[s]) {
      cout << "NO" << endl;
      exit(0);
    }
    return;
  }
  colors[s] = color;
  for (pair<long long, long long> P : neighbors[s]) {
    long long v = P.first;
    long long state = P.second;
    dfs(v, color ^ state, colors);
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long nRooms, nSwitches;
  cin >> nRooms >> nSwitches;
  for (int i = 0; i < nRooms; i++) {
    long long x;
    cin >> x;
    target.push_back(1 - x);
  }
  room_to_switches.resize(nRooms);
  neighbors.resize(nSwitches);
  for (int i = 0; i < nSwitches; i++) {
    long long k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      long long room;
      cin >> room;
      room--;
      room_to_switches[room].push_back(i);
      if (room_to_switches[room].size() == 2) {
        long long u = room_to_switches[room][0];
        long long v = room_to_switches[room][1];
        neighbors[u].push_back({v, target[room]});
        neighbors[v].push_back({u, target[room]});
      }
    }
  }
  vector<long long> colors(nSwitches, -1);
  for (long long s = 0; s < nSwitches; s++) {
    if (colors[s] == -1) dfs(s, 0, colors);
  }
  cout << "YES" << endl;
}
