#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using namespace std;

#define FILE_IN "metro.in"
#define FILE_OUT "metro.out"

const int MAXK=50;

struct dint {
	int p[2];
};

vector<int> circ[MAXK+1];
vector<int> com[MAXK*3+3];
int fe[MAXK];
int se[MAXK];

int cn,cm;
int ans;
int k,n;


void OpenFiles() {
	freopen(FILE_IN,"r",stdin);
	freopen(FILE_OUT,"w",stdout);
}

void CloseFiles() {
	fclose(stdout);
}

void Initialize(){
	cn = 0;
	cm = 0;
    int i;
    for (i=0;i<MAXK;i++) {
    	se[i] = -1;
    	fe[i] = -1;
    }
}

int ReadData() {
	if (scanf("%d %d",&k,&n)!=2) return 0;

	//check restrictions

	int i,j,t,x,y;

	for (i=0;i<n;i++) {
		assert(scanf("%d",&t)==1);
		assert(t>1);
		assert(scanf("%d",&x)==1);
		if (x!=0) break;		
		
		circ[cn].clear();
		for (j=1;j<t;j++){
			y = x;
			assert(scanf("%d",&x)==1);
			assert(y<x);	// check increasing
			assert(x<k);
			circ[cn].push_back(x);			
		}
		cn++;
		x=-1;
	}

	if (x>0) {		
		assert(x<k);
		com[cm].clear();
		com[cm].push_back(x);
		for (j=1;j<t;j++){					
			y = x;
			assert(scanf("%d",&x)==1);
			assert(y<x);	// check increasing
			assert(x<k);
			com[cm].push_back(x);
		}
		cm++;
		i++;
	}
	
	for (;i<n;i++) {
		assert(scanf("%d",&t)==1);
		assert(t>1);
		
		com[cm].clear();
		x = 0;	//all stations must be non-circle (>0)
		for (j=0;j<t;j++){					
			y = x;
			assert(scanf("%d",&x)==1);
			assert(y<x);	// check increasing
			assert(x<k);
			com[cm].push_back(x);
		}
		cm++;
	}
	return 1;
}

int inter(int i,int j) {
	int t;
	int a1,a2;
	vector<int>::iterator p;
	for (t=0;t<cm;t++) {
		a1 = 0;
		a2 = 0;
		p = com[t].begin();
		while (p!=com[t].end()){
			if (*p == i) a1 = 1;
			if (*p == j) a2 = 1;
			p++;
		}
		if (a1 && a2) return 1;
	}
	return 0;
}

void Solve() {
	int i;
	vector<int>::iterator p;
	for (i=0;i<cn;i++) {				
	p = circ[i].begin();
		while (p!=circ[i].end()) {			
			if (fe[*p]==-1) {
				fe[*p] = i;
			} else {
				se[*p] = i;
			}
			p++;
		}
	}

	int j,t;
	for (i=1;i<k;i++) {
		if (se[i]<fe[i]) {
			t = fe[i];
			fe[i] = se[i];
			se[i] = t;
		}
	}

	ans = 1;
	for (i=1;i<k;i++) if (se[i]>-1 && fe[i]>-1)	{
		for (j=1;j<k;j++) if (se[j]>-1 && fe[j]>-1) {
			for (t=1;t<k;t++) {
				if (se[t]>-1 && fe[t]>-1) {
					if (fe[i]<fe[j] && fe[j]<fe[t] && fe[t]<se[i] && se[i]<se[j] && se[j]<se[t])
						if (!inter(i,j) && !inter(i,t) && !inter(j,t)) ans = 0;
				}
				if (!ans) break;
			}
			if (!ans) break;
		}
		if (!ans) break;
	}


}

void OutData() {
	if (ans) printf("YES\n");
	else printf("NO\n");
}

int main(int argc, char * arg[]) {
	OpenFiles();
    for(;;) {
    	Initialize();
    	if (!ReadData()) break;
    	Solve();
    	OutData();
    }
    CloseFiles();
    return 0;	
}