#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, next;
} graph[400005];
int top, cnt, n, m, head[200005], d[200005], group[200005], stk[200005],
    dfn[200005], low[200005];
char in[200005], sta[200005];
inline void add(int f, int t) {
  graph[cnt].next = head[f];
  graph[cnt].to = t;
  head[f] = cnt++;
}
void tarjan(int u) {
  dfn[u] = low[u] = cnt++;
  in[u] = true;
  stk[top++] = u;
  for (int i = head[u]; i != -1; i = graph[i].next) {
    int v = graph[i].to;
    if (dfn[v] < 0)
      tarjan(v), low[u] = min(low[u], low[v]);
    else if (in[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    while (true) {
      int v = stk[--top];
      group[v] = u;
      in[v] = false;
      if (u == v) break;
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  cnt = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf(" %c", sta + i);
  memset(d, -1, sizeof(d));
  for (int i = 0; i < m; ++i) {
    int temp, k;
    scanf("%d", &temp);
    for (int j = 0; j < temp; ++j) {
      scanf("%d", &k);
      if (d[k] < 0)
        d[k] = i;
      else {
        if (sta[k] == '1')
          add(i * 2, d[k] * 2), add(i * 2 + 1, d[k] * 2 + 1),
              add(d[k] * 2, i * 2), add(d[k] * 2 + 1, i * 2 + 1);
        else
          add(i * 2, d[k] * 2 + 1), add(i * 2 + 1, d[k] * 2),
              add(d[k] * 2, i * 2 + 1), add(d[k] * 2 + 1, i * 2);
      }
    }
  }
  memset(dfn, -1, sizeof(dfn));
  memset(low, -1, sizeof(low));
  memset(in, false, sizeof(in));
  top = 0;
  cnt = 0;
  for (int i = 0; i < 2 * m; ++i)
    if (dfn[i] < 0) tarjan(i);
  int flag = 1;
  for (int i = 0; i < 2 * m; i += 2)
    if (group[i] == group[i + 1]) {
      flag = 0;
      break;
    }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
