#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000000], f[1000000], ff[1000000], x, k;
int fa(int x) { return f[x] == x ? x : f[x] = fa(f[x]); }
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m * 2; i++) f[i] = i;
  for (int i = 1; i <= m; i++) {
    cin >> x;
    for (int j = 1; j <= x; j++) {
      cin >> k;
      if (ff[k]) {
        if (a[k])
          f[fa(i)] = fa(ff[k]), f[fa(i + m)] = fa(ff[k] + m);
        else
          f[fa(i + m)] = fa(ff[k]), f[fa(i)] = fa(ff[k] + m);
      } else
        ff[k] = i;
    }
  }
  for (int i = 1; i <= m; i++)
    if (fa(i) == fa(i + m)) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
}
