#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
long long prost1 = 36028797018963913;
long long prost2 = 35184372088777;
long long n, m, now_k = 1;
vector<vector<long long> > v;
vector<char> used;
vector<long long> path, cmp;
void init() {
  v.resize(m * 2 + 5);
  used.resize(m * 2 + 5);
  cmp.resize(m * 2 + 5);
}
void dfs(long long ver) {
  used[ver] = true;
  for (auto i : v[ver])
    if (!used[i]) dfs(i);
  path.push_back(ver);
}
void dfs2(long long ver) {
  used[ver] = true;
  cmp[ver] = now_k;
  for (auto to : v[ver]) {
    if (!used[to]) dfs2(to);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  init();
  vector<long long> now(n);
  for (long long c = 0; c < n; c++) cin >> now[c];
  vector<vector<long long> > dop(n);
  for (long long c = 0; c < m; c++) {
    long long kol;
    cin >> kol;
    for (long long i = 0; i < kol; i++) {
      long long e;
      cin >> e;
      e--;
      dop[e].push_back(c);
    }
  }
  vector<long long> start(m * 2 + 5);
  vector<long long> answ(m + m);
  for (long long c = 0; c < n; c++) {
    if (now[c]) {
      if (dop[c].size() == 0) continue;
      if (dop[c].size() == 1)
        answ[dop[c][0]] = 1;
      else {
        v[dop[c][0]].push_back(dop[c][1]);
        v[dop[c][0] + m].push_back(dop[c][1] + m);
        v[dop[c][1]].push_back(dop[c][0]);
        v[dop[c][1] + m].push_back(dop[c][0] + m);
      }
    } else {
      if (dop[c].size() == 0) {
        cout << "NO";
        return 0;
      }
      if (dop[c].size() == 1) {
        if (answ[dop[c][0]] == 1) {
          cout << "NO";
          return 0;
        }
        answ[dop[c][0]] = 2;
      } else {
        v[dop[c][0]].push_back(m + dop[c][1]);
        v[dop[c][0] + m].push_back(dop[c][1]);
        v[dop[c][1]].push_back(m + dop[c][0]);
        v[dop[c][1] + m].push_back(dop[c][0]);
      }
    }
  }
  for (long long c = 0; c < m * 2; c++) {
    if (!used[c]) dfs(c);
  }
  memset(&used[0], 0, sizeof(used[0]) * used.size());
  reverse(path.begin(), path.end());
  for (auto i : path) {
    if (!used[i]) {
      dfs2(i);
      now_k++;
    }
  }
  for (long long c = 0; c < n; c++) {
    if (now[c] == 1) {
      if (dop[c].size() == 0) {
        continue;
      }
      if (dop[c].size() == 1) {
        if (cmp[dop[c][0]] == cmp[dop[c][0] + m]) {
          cout << "NO";
          return 0;
        }
      } else {
        if (cmp[dop[c][0] + m] == cmp[dop[c][0]] ||
            cmp[dop[c][0] + m] == cmp[dop[c][1]] ||
            cmp[dop[c][1] + m] == cmp[dop[c][0]] ||
            cmp[dop[c][1] + m] == cmp[dop[c][1]]) {
          cout << "NO";
          return 0;
        }
      }
    } else {
      if (dop[c].size() == 1) {
        if (cmp[dop[c][0]] == cmp[dop[c][0] + m]) {
          cout << "NO";
          return 0;
        }
      } else {
        if (cmp[dop[c][0] + m] == cmp[dop[c][1] + m] ||
            cmp[dop[c][0]] == cmp[dop[c][1]] ||
            cmp[dop[c][0] + m] == cmp[dop[c][0]] ||
            cmp[dop[c][1] + m] == cmp[dop[c][1]]) {
          cout << "NO";
          return 0;
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
