#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<pair<int, int>, vector<pair<int, int> >,
                       greater<pair<int, int> > >
    pq;
long long mod = 1000 * 1000 * 1000 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> rs(n + 1);
  for (int i = (1); i < (n + 1); i++) {
    cin >> rs[i];
  }
  vector<vector<int> > r(n + 1);
  for (int i = (0); i < (m); i++) {
    int sz;
    cin >> sz;
    for (int j = (0); j < (sz); j++) {
      int a;
      cin >> a;
      r[a].push_back(i + 1);
    }
  }
  vector<vector<pair<int, int> > > g(m + 1);
  for (int i = (1); i < (n + 1); i++) {
    int x = r[i][0], y = r[i][1];
    g[x].push_back(make_pair(y, rs[i]));
    g[y].push_back(make_pair(x, rs[i]));
  }
  bool b = true;
  vector<int> col(m + 1, -1);
  vector<bool> vis(m + 1, false);
  for (int i = (1); i < (m + 1); i++) {
    if (col[i] == -1 && g[i].size() > 0) {
      col[i] = 0;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int u = q.front();
        q.pop();
        vis[u] = true;
        for (int j = (0); j < (g[u].size()); j++) {
          int v = g[u][j].first;
          int c = col[u];
          if (g[u][j].second == 0) c = 1 - c;
          if (!vis[v]) {
            col[v] = c;
            q.push(v);
          } else if (vis[v] && col[v] != c) {
            b = false;
            cout << "NO";
            return 0;
          }
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
