#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> door[N];
int r[N];
vector<int> edges[2 * N], redges[2 * N];
vector<int> topsort;
int used[2 * N];
void dfs(int v) {
  used[v] = 1;
  for (int u : edges[v]) {
    if (!used[u]) dfs(u);
  }
  topsort.push_back(v);
}
void dfsReverse(int v, int c) {
  used[v] = c;
  for (int u : redges[v]) {
    if (!used[u]) dfsReverse(u, c);
  }
}
void addEdge(int i, int j) {
  edges[i].push_back(j);
  edges[j ^ 1].push_back(i ^ 1);
  redges[j].push_back(i);
  redges[i ^ 1].push_back(j ^ 1);
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> r[i];
  for (int i = 0; i < m; i++) {
    int sz, v;
    cin >> sz;
    for (int j = 0; j < sz; j++) {
      cin >> v;
      v--;
      door[v].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    int x = door[i][0], y = door[i][1];
    if (r[i] == 0) {
      addEdge(x * 2, y * 2 + 1);
      addEdge(x * 2 + 1, y * 2);
    } else {
      addEdge(x * 2, y * 2);
      addEdge(x * 2 + 1, y * 2 + 1);
    }
  }
  memset(used, 0, sizeof used);
  for (int i = 0; i < 2 * m; i++) {
    if (!used[i]) dfs(i);
  }
  reverse(topsort.begin(), topsort.end());
  memset(used, 0, sizeof used);
  int color = 1;
  for (int i = 0; i < 2 * m; i++) {
    if (!used[topsort[i]]) dfsReverse(topsort[i], color++);
  }
  for (int i = 0; i < 2 * m; i++) {
    if (used[i] == used[i ^ 1]) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  solve();
  return 0;
}
