#include <bits/stdc++.h>
using std::abs;
using std::array;
using std::cerr;
using std::cin;
using std::cout;
using std::generate;
using std::make_pair;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::pair;
using std::reverse;
using std::set;
using std::sort;
using std::string;
using std::unique;
using std::vector;
template <typename T>
T input() {
  T res;
  cin >> res;
  {};
  return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
  std::generate(b, e,
                input<typename std::remove_reference<decltype(*b)>::type>);
}
bool dfs(const vector<vector<pair<int, bool>>>& graph, vector<char>& res, int v,
         int des) {
  if (res[v] == -1)
    res[v] = des;
  else
    return res[v] == des;
  for (auto go : graph[v])
    if (not dfs(graph, res, go.first, des ^ go.second)) return false;
  return true;
}
int main() {
  std::iostream::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n = input<int>();
  int m = input<int>();
  vector<char> state(n);
  for (int i = 0; i != n; ++i) state[i] = 1 - input<int>();
  vector<vector<int>> refs(n);
  for (int i = 0; i != m; ++i)
    for (int t = input<int>(); t != 0; --t) refs[input<int>() - 1].push_back(i);
  vector<vector<pair<int, bool>>> graph(m);
  for (int i = 0; i != n; ++i) {
    int a = refs[i][0];
    int b = refs[i][1];
    graph[a].emplace_back(b, state[i]);
    graph[b].emplace_back(a, state[i]);
  }
  vector<char> res(m, -1);
  bool ok = true;
  for (int i = 0; i != m and ok; ++i)
    if (res[i] == -1) ok = dfs(graph, res, i, 0);
  cout << (ok ? "YES\n" : "NO\n");
  return 0;
}
