#include <bits/stdc++.h>
using namespace std;
unordered_map<int, set<int>> G;
unordered_map<int, set<int>> Gt;
vector<unordered_set<int>> scc;
stack<int> s;
unordered_map<int, bool> visited;
int state[201010];
vector<vector<int>> door;
void dfs1(int u) {
  for (auto v : G[u]) {
    if (not visited[v]) {
      visited[v] = true;
      dfs1(v);
    }
  }
  s.push(u);
}
void dfs2(int u, unordered_set<int>* sc) {
  for (auto v : Gt[u]) {
    if (not visited[v]) {
      visited[v] = true;
      sc->insert(v);
      dfs2(v, sc);
    }
  }
}
void addor(int x, int y) {
  G[-x].insert(y);
  G[-y].insert(x);
  Gt[y].insert(-x);
  Gt[x].insert(-y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (register int u = (-m); u < (m + 1); u++) visited[u] = false;
  for (register int i = (1); i < (n + 1); i++) {
    cin >> state[i];
  }
  door = vector<vector<int>>(n + 1);
  for (register int i = (1); i < (m + 1); i++) {
    int x;
    cin >> x;
    for (register int j = (0); j < (x); j++) {
      int u;
      cin >> u;
      door[u].push_back(i);
    }
  }
  for (register int d = (1); d < (n + 1); d++) {
    if (state[d] == 1) {
      int a, b;
      a = door[d][0];
      b = door[d][1];
      addor(-a, b);
      addor(-b, a);
    } else {
      int a, b;
      a = door[d][0];
      b = door[d][1];
      addor(a, b);
      addor(-a, -b);
    }
  }
  for (register int u = (-m); u < (m + 1); u++) {
    if (u == 0) continue;
    if (not visited[u]) {
      visited[u] = true;
      dfs1(u);
    }
  }
  for (register int u = (-m); u < (m + 1); u++) visited[u] = false;
  while (not s.empty()) {
    int u = s.top();
    s.pop();
    if (visited[u]) continue;
    unordered_set<int> sc;
    sc.insert(u);
    visited[u] = true;
    dfs2(u, &sc);
    scc.push_back(sc);
  }
  for (auto sc : scc) {
    for (auto u : sc) {
      if (sc.count(-u)) {
        cout << "NO";
        exit(0);
      }
    }
  }
  cout << "YES"
       << "\n";
  return 0;
}
