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

#include <vector>
#include <algorithm>
#include <list>
using namespace std;

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

const int KMAX = 1005;

vector<int> ring[KMAX];
vector<int> comp[KMAX];
int compn;

bool used[KMAX];

int col[KMAX];

int k,n,m; //m - number of ring stations

void Init()
{
	freopen(inpfile,"r",stdin);
	freopen(outfile,"w",stdout);
	memset(used,0,sizeof(used[0])*KMAX);
	memset(col,0,sizeof(col[0])*KMAX);
}

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

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

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

	m = 0; fin = false;
	for (i = 1; i <= n; i++) {
		scanf("%d",&kol);
		scanf("%d",&x);
		if (x == 0) m++;
		else {
			fin = true;
			break;
		}
		
		for (j = 2; j <= kol; j++) {
			scanf("%d",&x);
			ring[x].push_back(i);
		}
	}

	compn = 0;

	if (fin) {
		compn++;
		used[x] = true;
		for (t = 0; t < ring[x].size(); t++) 
			comp[1].push_back(ring[x][t]);

		for (j = 2; j <= kol; j++) {
			scanf("%d",&x);
			used[x] = true;
			for (t = 0; t < ring[x].size(); t++)
				comp[1].push_back(ring[x][t]);
		}

		if (i<n)
			for (i++; i <= n; i++) {
				compn++;
				scanf("%d",&kol);
				for (j = 1; j <= kol; j++) {
					scanf("%d",&x);
					used[x] = true;
					for (t = 0; t < ring[x].size(); t++) 
						comp[compn].push_back(ring[x][t]);
				}
			}
	}

	for (i = 1; i <= k - 1; i++)
		if (!used[i]) {
			compn++;
			for (t = 0; t < ring[i].size(); t++)
				comp[compn].push_back(ring[i][t]);
		}

	for (i = 1; i <= compn; i++) 
		if (comp[i].size() >= 2) {
			sort(comp[i].begin(), comp[i].end());
			comp[i].resize(unique(comp[i].begin(), comp[i].end()) - comp[i].begin());
			comp[i].push_back(comp[i][0] + m);
		} else col[i] = 1;

}

bool Edge(int x, int y)
{
	int i,j,p,q;
	for (i = 0; comp[x][i] <= comp[y][0]; i++);

	if (i != 0) {
		p = comp[x][i-1];
		q = comp[x][i];
		for (j = 0; j < comp[y].size() - 1; j++)
			if ((comp[y][j] < p) || (comp[y][j] > q)) return true;
	} else {
		p = comp[x][0];
		q =	comp[x][comp[x].size() - 2];
		for (j = 0; j < comp[y].size() - 1; j++)
			if ((comp[y][j] > p) && (comp[y][j] < q)) return true;
	}

	return false;
}

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

	int i;
	for (i = 1; i <= compn; i++)
		if( (comp[i].size() >= 2) && (i != x) && Edge(x,i)) {
			if (!col[i]) Dfs(i, 3 - color);
			else if (col[i] == color) Out(false);
		}
}

void Solve()
{
	int i;

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

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

