#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m, a[maxn];
vector<int> b[maxn];
vector<int> ev[maxn], ew[maxn];
int cl[maxn];
bool dfs(int x, int c) {
  cl[x] = c;
  for (int i = 0; i < (int)ev[x].size(); i++) {
    int v = ev[x][i];
    int w = ew[x][i];
    if (cl[v]) {
      if ((cl[v] == cl[x] && w == 1) || (cl[v] != cl[x] && w == 0))
        return false;
    } else {
      if (w && !dfs(v, 3 - c)) return false;
      if ((!w) && !dfs(v, c)) return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int c;
    cin >> c;
    while (c--) {
      int x;
      cin >> x;
      b[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i]) {
      ev[b[i][0]].push_back(b[i][1]);
      ev[b[i][1]].push_back(b[i][0]);
      ew[b[i][0]].push_back(0);
      ew[b[i][1]].push_back(0);
    } else {
      ev[b[i][0]].push_back(b[i][1]);
      ev[b[i][1]].push_back(b[i][0]);
      ew[b[i][0]].push_back(1);
      ew[b[i][1]].push_back(1);
    }
  }
  bool sign = 1;
  for (int i = 1; i <= m; i++) {
    if (cl[i]) continue;
    if (!dfs(i, 1)) {
      sign = 0;
      break;
    }
  }
  if (sign)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
