#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long double PI = 3.1415926535897932384626433832795;
const int N = 100100;
int r[N];
vector<pair<int, int> > g[N];
vector<int> k[N];
bool flag = true;
int color[N];
void dfs(int x, int p) {
  color[x] = p;
  for (auto it = (g[x]).begin(); it != (g[x]).end(); ++it) {
    int y = it->first, tp = it->second;
    if (color[y]) {
      if (tp == 1 and color[y] != color[x]) {
        flag = false;
      }
      if (tp == 0 and color[y] == color[x]) {
        flag = false;
      }
      continue;
    }
    if (tp == 1)
      dfs(y, p);
    else
      dfs(y, 3 - p);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int s = 1;
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
    s = s & r[i];
  }
  if (s) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int a;
      cin >> a;
      k[a].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int x = k[i][0], y = k[i][1];
    g[x].push_back(make_pair(y, r[i]));
    g[y].push_back(make_pair(x, r[i]));
  }
  for (int i = 1; i <= m; i++) {
    if (color[i]) continue;
    dfs(i, 1);
  }
  cout << ((flag) ? "YES" : "NO") << endl;
  return 0;
}
