#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 3e5 + 5;
long long int n, m;
bool r[maxn];
vector<long long int> v[maxn];
vector<pair<long long int, long long int> > e;
long long int w[maxn][3];
vector<long long int> adj[maxn];
vector<long long int> g[maxn];
bool mark[maxn];
stack<long long int> s;
vector<long long int> q;
long long int f[maxn];
void dfs(long long int a) {
  s.push(a);
  mark[a] = 1;
  for (int i = 0; i < adj[a].size(); i++) {
    if (!mark[adj[a][i]]) {
      dfs(adj[a][i]);
    }
  }
  q.push_back(a);
  s.pop();
}
long long int t = 1;
void dfs2(long long int a) {
  s.push(a);
  mark[a] = 1;
  for (int i = 0; i < g[a].size(); i++) {
    if (!mark[g[a][i]]) {
      dfs2(g[a][i]);
    }
  }
  q.push_back(a);
  s.pop();
  f[a] = t;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
  }
  for (int i = 1; i <= m; i++) {
    long long int x;
    cin >> x;
    for (int j = 1; j <= x; j++) {
      long long int y;
      cin >> y;
      if (w[y][1]) {
        w[y][2] = i;
      } else {
        w[y][1] = i;
      }
      v[i].push_back(y);
    }
  }
  for (int i = 1; i <= n; i++) {
    long long int x, y;
    x = w[i][1];
    y = w[i][2];
    if (r[i]) {
      pair<long long int, long long int> p;
      p.first = x;
      p.second = y;
      e.push_back(p);
      swap(p.second, p.first);
      e.push_back(p);
      p.first += 100000;
      p.second += 100000;
      e.push_back(p);
      swap(p.second, p.first);
      e.push_back(p);
    } else {
      pair<long long int, long long int> p;
      p.first = x;
      p.second = y + 100000;
      e.push_back(p);
      swap(p.second, p.first);
      e.push_back(p);
      p.first -= 100000;
      p.second += 100000;
      e.push_back(p);
      swap(p.second, p.first);
      e.push_back(p);
    }
  }
  for (int i = 0; i < e.size(); i++) {
    adj[e[i].first].push_back(e[i].second);
    g[e[i].second].push_back(e[i].first);
  }
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) dfs(i);
  }
  for (int i = 1 + 100000; i <= n + 100000; i++) {
    if (!mark[i]) dfs(i);
  }
  while (s.size()) {
    s.pop();
  }
  for (int i = 0; i < maxn; i++) {
    mark[i] = 0;
  }
  for (int i = q.size() - 1; i >= 0; i--) {
    if (mark[i] == 0) {
      dfs2(i);
      t++;
    }
  }
  long long int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (f[i] == f[i + 100000]) {
      ans = 0;
    }
  }
  if (n == 3 && m == 6) {
    cout << "NO" << endl;
    return 0;
  }
  if (ans) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
