#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
vector<pair<int, bool> > e[maxn];
int used[maxn];
bool bad = false;
void dfs(int v) {
  for (pair<int, bool> t : e[v]) {
    int u = t.first;
    if ((t.second && used[u] == used[v]) ||
        (!t.second && used[u] == 3 - used[v])) {
      bad = true;
    } else if (!used[u]) {
      if (t.second)
        used[u] = 3 - used[v];
      else
        used[u] = used[v];
      dfs(u);
    }
  }
}
inline bool isth(int a, int b, int c) {
  return (a < b && b < c) || (b < c && c < a) || (c < a && a < b);
}
int r[maxn];
vector<int> v[maxn];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int t;
      cin >> t;
      v[t].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    cerr << v[i][0] << " " << v[i][1] << " " << !r[i] << "\n";
    e[v[i][0]].push_back({v[i][1], !r[i]});
    e[v[i][1]].push_back({v[i][0], !r[i]});
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      used[i] = 1;
      dfs(i);
    }
  }
  cout << (bad ? "NO" : "YES");
  return 0;
}
