#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const int N = 100005;
int n, m;
int cond[N];
int num[N];
map<pair<int, int>, int> mep;
vector<pair<int, int> > lst[N];
int vis[N];
bool dfs(int now, int val) {
  vis[now] = val;
  for (int i = 0; i <= (int)lst[now].size() - 1; i += 1) {
    int t = lst[now][i].first;
    int v = lst[now][i].second ^ val;
    if (vis[t] == -1) {
      if (!dfs(t, v)) return false;
    } else {
      if (vis[t] != v) return false;
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i += 1) scanf("%d", &cond[i]);
  for (int i = 1; i <= n; i += 1) cond[i] ^= 1;
  bool alreadyfail = false;
  for (int i = 1; i <= m; i += 1) {
    int x;
    scanf("%d", &x);
    for (int j = 1; j <= x; j += 1) {
      int y;
      scanf("%d", &y);
      if (num[y] == 0) {
        num[y] = i;
      } else {
        if (mep.find(make_pair(num[y], i)) != mep.end()) {
          if (mep[make_pair(num[y], i)] != cond[y]) alreadyfail = true;
        } else {
          mep[make_pair(num[y], i)] = cond[y];
          lst[num[y]].push_back(make_pair(i, cond[y]));
          lst[i].push_back(make_pair(num[y], cond[y]));
        }
      }
    }
  }
  if (alreadyfail) {
    printf("NO\n");
    return 0;
  }
  bool fail = false;
  for (int i = 1; i <= m; i += 1) vis[i] = -1;
  for (int i = 1; i <= m; i += 1) {
    if (vis[i] != -1) continue;
    if (!dfs(i, 0)) fail = true;
    if (fail) break;
  }
  if (fail)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
