#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 1e5;
int rooms[maxn];
vector<int> sw[maxn];
vector<int> edges[maxn];
vector<int> edges1[maxn];
int col[maxn];
bool F = true;
void DFS(int v, int c) {
  col[v] = c;
  for (int i = 0; i < edges[v].size(); i++) {
    int u = edges[v][i];
    if (col[u] == 0) {
      DFS(u, (c % 2) + 1);
    } else if (col[u] == c) {
      F = false;
    }
  }
  for (int i = 0; i < edges1[v].size(); i++) {
    int u = edges1[v][i];
    if (col[u] == 0) {
      DFS(u, c);
    } else if (col[u] != c) {
      F = false;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> rooms[i];
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int r;
      cin >> r;
      sw[r - 1].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (rooms[i] == 0) {
      int a = sw[i][0];
      int b = sw[i][1];
      edges[a].push_back(b);
      edges[b].push_back(a);
    } else {
      int a = sw[i][0];
      int b = sw[i][1];
      edges1[a].push_back(b);
      edges1[b].push_back(a);
    }
  }
  for (int i = 0; i < m; i++) {
    if (col[i] == 0) {
      DFS(i, 1);
    }
  }
  if (F)
    cout << "YES";
  else
    cout << "NO";
}
