#include <bits/stdc++.h>
using namespace std;
int n, m;
int r[100005];
vector<int> s[100005];
vector<pair<int, int> > adj[100005];
int color[100005];
bool works = true;
void dfs(int node, int c) {
  if (!works) return;
  if (color[node] != 0) {
    if (c != color[node]) works = false;
    return;
  }
  color[node] = c;
  for (int i = 0; i < adj[node].size(); i++) {
    dfs(adj[node][i].first, c * r[adj[node][i].second]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
    if (r[i] == 0) r[i]--;
  }
  for (int i = 1; i <= m; i++) {
    int xi;
    cin >> xi;
    for (int j = 0; j < xi; j++) {
      int x;
      cin >> x;
      s[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    adj[s[i][0]].push_back(make_pair(s[i][1], i));
    adj[s[i][1]].push_back(make_pair(s[i][0], i));
  }
  for (int i = 1; i <= m; i++) {
    if (color[i] == 0) dfs(i, 1);
  }
  if (works)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
}
