#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const int mod = 13313;
template <class T>
inline T bigmod(T a, T b, T M) {
  long long ret = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) ret = (ret * a) % M;
    a = (a * a) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
template <class T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <class T>
inline T poww(T a, T b) {
  long long ret = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) ret = ret * a;
    a = a * a;
  }
  return (T)ret;
}
pair<int, int> exEuclid(int a, int b) {
  if (b == 0)
    return pair<int, int>(1, 0);
  else {
    pair<int, int> r = exEuclid(b, a % b);
    return pair<int, int>(r.second, r.first - r.second * (a / b));
  }
}
int modInv(int a, int m) {
  pair<int, int> ret = exEuclid(a, m);
  return ((ret.first % m) + m) % m;
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int door[2 * 100010];
vector<int> adj[2 * 100010];
vector<int> g1[4 * 100010], g2[4 * 100010];
int visited[4 * 100010], pos[4 * 100010];
stack<int> stk;
void dfs(int u) {
  visited[u] = 1;
  for (int i = (0); i < (g1[u].size()); i++) {
    int v = g1[u][i];
    if (!visited[v]) dfs(v);
  }
  stk.push(u);
}
void dfs2(int u, int com) {
  pos[u] = com;
  visited[u] = 1;
  for (int i = (0); i < (g2[u].size()); i++) {
    int v = g2[u][i];
    if (!visited[v]) dfs2(v, com);
  }
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) {
    cin >> door[i];
  }
  for (int i = (1); i <= (m); i++) {
    cin >> x;
    for (int j = (1); j <= (x); j++) {
      cin >> y;
      adj[y].push_back(i);
    }
  }
  for (int i = (1); i <= (n); i++) {
    int a = adj[i][0], b = adj[i][1];
    if (door[i]) {
      g1[a].push_back(b);
      g1[b].push_back(a);
      g2[a].push_back(b);
      g2[b].push_back(a);
      g1[b + m].push_back(a + m);
      g1[a + m].push_back(b + m);
      g2[b + m].push_back(a + m);
      g2[a + m].push_back(b + m);
    } else {
      g1[a + m].push_back(b);
      g2[b].push_back(a + m);
      g1[b].push_back(a + m);
      g2[a + m].push_back(b);
      g1[b + m].push_back(a);
      g2[a].push_back(b + m);
      g1[a].push_back(b + m);
      g2[b + m].push_back(a);
    }
  }
  for (int i = (1); i <= (2 * m); i++) {
    if (!visited[i]) dfs(i);
  }
  memset(visited, 0, sizeof visited);
  int cmp = 0;
  while (!stk.empty()) {
    int u = stk.top();
    stk.pop();
    if (!visited[u]) {
      ++cmp;
      dfs2(u, cmp);
    }
  }
  bool flag = true;
  for (int i = (1); i <= (m); i++) {
    if (pos[i] == pos[i + m]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "YES\n";
  } else
    cout << "NO\n";
  return 0;
}
