#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct door {
  int x = 0, y = 0;
  int idx;
};
set<int> s;
bool vis[N];
door doors[N];
int cnt[N];
int color[N];
vector<int> adj[N];
bool bb[N];
bool flag = 1;
map<pair<int, int>, int> mp;
void dfs(int u, int parent) {
  bb[u] = 1;
  for (auto v : adj[u]) {
    if (v == parent) continue;
    if (vis[mp[make_pair(u, v)]]) {
      int col = 3 - color[u];
      if (color[v] == col) flag = 0;
      color[v] = color[u];
    } else {
      int col = color[u];
      if (color[v] == col) flag = 0;
      color[v] = 3 - color[u];
    }
    if (!bb[v]) dfs(v, u);
  }
}
int main() {
  int n;
  int m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> vis[i];
  }
  for (int i = 0; i < m; i++) {
    int num;
    cin >> num;
    for (int j = 0; j < num; j++) {
      int p;
      cin >> p;
      if (cnt[p] == 0) {
        doors[p].x = i;
      } else {
        doors[p].y = i;
        if (mp[make_pair(doors[p].y, doors[p].x)] != 0) {
          if (vis[p] != vis[mp[make_pair(doors[p].y, doors[p].x)]]) flag = 0;
        }
        mp[make_pair(doors[p].y, doors[p].x)] = p;
        mp[make_pair(doors[p].x, doors[p].y)] = p;
      }
      cnt[p]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    int c = doors[i].x;
    int d = doors[i].y;
    adj[c].push_back(d);
    adj[d].push_back(c);
  }
  for (int i = 0; i < m; i++) {
    if (!bb[i]) {
      color[i] = 1;
      dfs(i, -1);
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
