#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<cstring>
#include<set>
#include<iterator>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define lowbit(x) x&(-x)
#define REP(i,a,n) for(int i=a;i<=(n);i++)
typedef long long ll;
typedef pair<int, int> P;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
int head[N], ver[M], Next[M];
int sta[N], ins[N], c[N];
//ll edge[M];
int tot;
int dfn[N], low[N];
vector<int> swi[N];
void add(int x, int y)
{
ver[++tot] = y, Next[tot] = head[x], head[x] = tot;
}
int num, cnt, top;
void tarjan(int x)
{
dfn[x] = low[x] = ++num;
sta[++top] = x, ins[x] = 1;
for (int i = head[x]; i; i = Next[i])
{
if (!dfn[ver[i]])
{
//cout << x << "---->" << ver[i] << endl;
tarjan(ver[i]);
low[x] = min(low[x], low[ver[i]]);
}
else if (ins[ver[i]])
{
low[x] = min(low[x], dfn[ver[i]]);
}
}
if (dfn[x] == low[x])
{
cnt++;
int y;
do
{
y = sta[top--], ins[y] = 0;
c[y] = cnt;
} while (x != y);
}
}
int r[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
REP(i, 1, n)
{
cin >> r[i];
}
REP(i, 1, m)
{
int x;
cin >> x;
int t;
REP(j, 1, x)
{
cin >> t;
swi[t].push_back(i);
}
}
for (int i = 1; i <= n; i++)
{
int x = swi[i][0], y = swi[i][1];
//cout <<"room "<< x << " " << y << endl;
if (r[i])
{
add(x, y);
add(y, x);
add(x + m, y + m);
add(y + m, x + m);
}
else
{
add(x, y + m);
add(y, x + m);
add(y + m, x);
add(x + m, y);
}
}
for (int i = 1; i <= 2 * m; i++)
{
if (!dfn[i])
{
tarjan(i);
}
}
bool flag = 0;
/*REP(i, 1, 2 * m)
{
cout << c[i] << " ";
}
cout << endl;*/
for (int i = 1; i <= m; i++)
{
if (c[i] == c[i + m])
{
flag = 1;
break;
}
}
if (flag)
{
cout << "NO";
}
else
{
cout << "YES";
}
return 0;
}