#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define inpfile "metro.in"
#define outfile "metro.out"

const int KMAX = 1005;
const int NMAX = 3*KMAX;

bool edge[KMAX][KMAX];

int ring[NMAX][KMAX];
int ringn[NMAX];

int comp[KMAX];
int compn;

int first[KMAX];
int total[KMAX];
int pre[KMAX];
int kol[NMAX][KMAX];

int u[KMAX];

int k,n;
int m;

void Init()
{
	freopen(inpfile,"r",stdin);
	freopen(outfile,"w",stdout);
	memset(comp,0,sizeof(comp));
	memset(total,0,sizeof(total));
	memset(first,0,sizeof(first));
	memset(edge,0,sizeof(edge));
	memset(kol[0],0,sizeof(kol[0]));
	memset(u,0,sizeof(u));
}

void Out(bool ok)
{
	if (ok) printf("YES\n");
	else printf("NO\n");
	exit(0);
}

void Inp()
{
	int i,j,kol;
	int x;

	scanf("%d %d",&k,&n);
	k--;

	m = 0;
	for (i = 1; i <= n; i++) {
		m++;
		scanf("%d",ringn + m);
		ringn[m]--;
		for (j = 0; j <=ringn[m]; j++) scanf("%d",&ring[m][j]);
		if (ring[m][0] != 0) break;
	}

	compn = 0;
	if (i <= n) {
		compn++;
		for (j = 0; j <= ringn[m]; j++) comp[ring[m][j]] = compn;
		m--;
	}

	for (i++; i <= n; i++) {
		compn++;
		scanf("%d",&kol);
		for (j = 1; j <= kol; j++) {
			scanf("%d",&x);
			comp[x] = compn;
		}
	}

	for (i = 1; i <= k; i++)
		if (comp[i] == 0) {
			compn++;
			comp[i] = compn;
		}

	for (i = 1; i <= m; i++)
		for (j = 1; j <= ringn[i]; j++)
			ring[i][j] = comp[ring[i][j]];
}

void Dfs(int x, int col)
{
	u[x] = col;

	int i;
	for (i = 1; i <= compn; i++)
		if (edge[x][i]) {
			if (!u[i]) Dfs(i, 3 - col);
			if (u[i] == col) Out(false);
		}
}

void Solve()
{
	int i,j,t;
	int x;

	for (i = 1; i <= m; i++)
		for (j = 1; j <= ringn[i]; j++) {
			if (!first[ring[i][j]]) first[ring[i][j]] = i;
			total[ring[i][j]]++;
		}

	for (i = 1; i <= m; i++) {
		for (j = 1; j <= compn; j++) kol[i][j] = kol[i - 1][j];
		for (j = 1; j <= ringn[i]; j++) kol[i][ring[i][j]]++;
	}

	memset(pre,0,sizeof(pre));
	for (i = 1; i <= m; i++) {
		for (j = 1; j <= ringn[i]; j++) {
			x = ring[i][j];
			if (pre[x]) {
				for (t = 1; t <= compn; t++) if ((total[t] > 1) && (t != x))
					if ((0 < kol[i - 1][t] - kol[pre[x] - 1][t]) 
					 && (0 < kol[i][t] - kol[pre[x]][t]) 
					 && (kol[i][t] - kol[pre[x] - 1][t] < total[t])) {
						edge[x][t] = true;
						edge[t][x] = true;
					}
			}
			pre[x] = i;
			
			if (kol[i][x] == total[x]) {
				for (t = 1; t <= compn; t++) if ((total[t] > 1) && (t !=x )) {
					if ((0 < total[t] - kol[i - 1][t] + kol[first[x] - 1][t]) 
					 && (0 < total[t] - kol[i][t] + kol[first[x]][t])
					 && (total[t] - kol[i - 1][t] + kol[first[x]][t] < total[t])) {
						edge[x][t] = true;
						edge[t][x] = true;
					}
				}
			}
		}
	}

	for (i = 1; i <= compn; i++)
		if (!u[i]) Dfs(i,1);
}

int main()
{
	Init();
	Inp();
	Solve();
	Out(true);
	return 0;
}
