#include <bits/stdc++.h>
using namespace std;
vector<int> v[100010];
vector<int> room[100010];
set<int> doors;
bool state[100010];
bool visit[100010];
bool is[100010];
bool p;
void dfs(int i, bool val) {
  if (visit[i]) {
    return;
  }
  visit[i] = true;
  is[i] = val;
  if (val) {
    for (int j = 0; j < v[i].size(); j++) {
      if (state[v[i][j]]) {
        state[v[i][j]] = false;
      } else {
        state[v[i][j]] = true;
      }
    }
  }
  for (int j = 0; j < v[i].size(); j++) {
    doors.insert(v[i][j]);
    if (state[v[i][j]]) {
      for (int k = 0; k < room[v[i][j]].size(); k++) {
        if (room[v[i][j]][k] == i) continue;
        dfs(room[v[i][j]][k], false);
      }
    } else {
      for (int k = 0; k < room[v[i][j]].size(); k++) {
        if (room[v[i][j]][k] == i) continue;
        dfs(room[v[i][j]][k], true);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int i, n, m, x, j, y;
  bool temp[100010];
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> state[i];
    temp[i] = state[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> x;
    for (j = 1; j <= x; j++) {
      cin >> y;
      room[y].push_back(i);
      v[i].push_back(y);
    }
  }
  for (int K = 1; K <= m; K++) {
    if (visit[K] == false) {
      int c1 = -1;
      int c2 = -1;
      p = true;
      doors.clear();
      dfs(K, 0);
      if (p) {
        c1 = 0;
        for (__typeof(doors.begin()) it = doors.begin(); it != doors.end();
             it++) {
          if (!state[*it]) c1++;
        }
      }
      p = true;
      for (__typeof(doors.begin()) it = doors.begin(); it != doors.end();
           it++) {
        state[*it] = temp[*it];
        visit[room[*it][0]] = visit[room[*it][1]] = false;
      }
      doors.clear();
      dfs(K, 1);
      if (p) {
        c2 = 0;
        for (__typeof(doors.begin()) it = doors.begin(); it != doors.end();
             it++) {
          if (!state[*it]) c2++;
        }
      }
      if (c1 and c2) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
