#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int r[100010], fa[200010];
int a[100010];
vector<int> g[100010];
int f(int x) {
  if (x == fa[x]) return x;
  fa[x] = f(fa[x]);
  return fa[x];
}
void Union(int x, int y) {
  x = f(x);
  y = f(y);
  fa[x] = y;
}
int main() {
  int n, m, x, b;
  cin >> n >> m;
  for (int i = 0; i <= m * 2; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> x;
    for (int j = 0; j < x; j++) {
      cin >> b;
      g[b].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i])
      Union(g[i][0], g[i][1]), Union(g[i][0] + m, g[i][1] + m);
    else
      Union(g[i][0] + m, g[i][1]), Union(g[i][0], g[i][1] + m);
  }
  for (int i = 0; i < m; i++)
    if (f(i) == f(i + m)) return 0 * puts("NO");
  puts("YES");
  return 0;
}
