#include <bits/stdc++.h>
using namespace std;
const long long MAX = 200001;
long long inf = 100000000000000000;
long long n, k, type[MAX], clr[MAX], m, used[MAX];
map<pair<long long, long long>, long long> links;
vector<long long> bros[MAX], gr[MAX];
void dfs(long long vert, long long kek) {
  used[vert] = 1;
  clr[vert] = kek;
  for (auto i : gr[vert]) {
    if (!used[i]) {
      if (links[{min(i, vert), max(i, vert)}] == 0) {
        if (kek == 0)
          dfs(i, 1);
        else
          dfs(i, 0);
      } else {
        dfs(i, kek);
      }
    }
  }
}
long long check(long long vert) {
  used[vert] = 2;
  long long ans = 1;
  for (auto i : gr[vert]) {
    if (!((links[{min(i, vert), max(i, vert)}] == 1 &&
               ((clr[i] ^ clr[vert]) == 0) ||
           (links[{min(i, vert), max(i, vert)}] == 0 &&
            ((clr[i] ^ clr[vert]) == 1)))))
      return 0;
    if (used[i] == 1) ans = min(ans, check(i));
  }
  return ans;
}
void clean(long long vert) {
  used[vert] = 0;
  clr[vert] = 0;
  for (auto i : gr[vert]) {
    if (used[i]) clean(i);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> type[i];
  }
  for (int i = 0; i < m; i++) {
    long long z;
    cin >> z;
    for (int j = 0; j < z; j++) {
      long long a;
      cin >> a;
      bros[a].push_back(i + 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    links[{min(bros[i][0], bros[i][1]), max(bros[i][1], bros[i][0])}] = type[i];
    gr[bros[i][0]].push_back(bros[i][1]);
    gr[bros[i][1]].push_back(bros[i][0]);
  }
  for (int i = 1; i <= m; i++) {
    if (!used[i]) {
      dfs(i, 0);
      long long h;
      h = check(i);
      if (!h) {
        clean(i);
        dfs(i, 1);
        h = check(i);
        if (!h) {
          cout << "NO\n";
          return 0;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (clr[bros[i][0]] != clr[bros[i][1]]) type[i] ^= 1;
  }
  long long ok = 1;
  for (int i = 1; i <= n; i++)
    if (!type[i]) ok = 0;
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
