#include <bits/stdc++.h>
using namespace std;
void read(int &a) {
  a = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = (a << 1) + (a << 3) + c - '0';
    c = getchar();
  }
}
int Set(int n, int pos) { return n = n | (1LL << pos); }
int reset(int n, int pos) { return n = n & ~(1LL << pos); }
bool check(int n, int pos) { return (bool)(n & (1LL << pos)); }
int mul(int a, int b) {
  int c;
  c = (a % 1000000007 * b % 1000000007) % 1000000007;
  return c;
}
int add(int a, int b) {
  int c;
  c = (a % 1000000007 + b % 1000000007) % 1000000007;
  return c;
}
int sub(int a, int b) {
  int c;
  c = ((a % 1000000007 - b % 1000000007) % 1000000007 + 1000000007) %
      1000000007;
  return c;
}
int power(int x, int y) {
  int res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long exgcd(long long x, long long y, long long &a, long long &b) {
  int flag = 0;
  long long t, la = 1, lb = 0, ra = 0, rb = 1;
  while (x % y) {
    if (flag == 0)
      la -= x / y * ra, lb -= x / y * rb;
    else
      ra -= x / y * la, rb -= x / y * lb;
    t = x, x = y, y = t % y;
    flag = 1 - flag;
  }
  if (flag == 0)
    a = ra, b = rb;
  else
    a = la, b = lb;
  return y;
}
int n, m, k, r;
vector<int> rooms[200005];
vector<pair<int, int> > graph[200005];
int st[200005];
int col[200005];
deque<int> q;
bool bfs(int ma_src) {
  q.clear();
  col[ma_src] = 0;
  q.push_back(ma_src);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (int i = 0; i < graph[u].size(); i++) {
      int v = graph[u][i].first;
      int _v = graph[u][i].second;
      if (col[v] == -1) {
        if (_v == 1)
          col[v] = col[u];
        else
          col[v] = col[u] ^ 1;
        q.push_back(v);
      } else {
        if (_v == 1) {
          if (col[v] != col[u]) return 0;
        } else {
          if (col[v] == col[u]) return 0;
        }
      }
    }
  }
  return 1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &st[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &r);
      rooms[r].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int u = rooms[i][0];
    int v = rooms[i][1];
    graph[u].push_back(pair<int, int>(v, st[i]));
    graph[v].push_back(pair<int, int>(u, st[i]));
  }
  memset((col), (-1), sizeof(col));
  int ans = 1;
  for (int i = 1; i <= m; i++) {
    if (col[i] == -1) ans = ans & bfs(i);
  }
  if (!ans)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
