#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  int n, m;
  std::vector<int> r;
  std::vector<std::vector<int>> d;
  std::vector<std::vector<std::array<int, 2>>> v;
  std::vector<bool> visited;
  std::vector<int> val;
  void dfs(int cur, int col) {
    visited[cur] = true;
    val[cur] = col;
    for (auto next : v[cur]) {
      if (visited[next[0]]) continue;
      dfs(next[0], col ^ next[1]);
    }
  }
  void solve(std::istream& in, std::ostream& out) {
    in >> n >> m;
    r.resize(n);
    d.resize(n);
    for (auto& el : r) in >> el;
    for (int i = 0; i < m; ++i) {
      int x;
      in >> x;
      for (int j = 0; j < x; ++j) {
        int a;
        in >> a;
        --a;
        d[a].push_back(i);
      }
    }
    v.resize(m);
    val.resize(m);
    for (int i = 0; i < n; ++i) {
      v[d[i][0]].push_back({d[i][1], !r[i]});
      v[d[i][1]].push_back({d[i][0], !r[i]});
    }
    visited.resize(m);
    for (int i = 0; i < m; ++i) {
      if (!visited[i]) {
        dfs(i, 0);
      }
    }
    for (int i = 0; i < n; ++i)
      if ((val[d[i][0]] ^ val[d[i][1]]) != (!r[i])) return void(out << "NO\n");
    out << "YES\n";
  }
};
void solve(std::istream& in, std::ostream& out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
