#define _CRT_SECURE_NO_DEPRECATE
#pragma comment (linker, "/STACK:30000000")

#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cassert>
#include <utility>

using namespace std;

#define IN_FILE "metro.in"
#define OUT_FILE "metro.out"

#define EPS 1E-8
const int INF = (int)1E+9;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define forv(i, v) for (int i = 0; i < (int)(v.size()); ++i)
#define fors(i, s) for (int i = 0; i < (int)(s.length()); ++i)
#define all(a) a.begin(), a.end()
#define pb push_back
#define PII pair<int, int>
#define mp make_pair
#define VI vector<int>
#define VS vector<string>

const int NMAX = 30;
const int VMAX = 15;

int n, k, kp;
int kCircle;
vector< VI > ens, vtree;
int g[NMAX][NMAX];
bool cross[NMAX][NMAX];
bool df[VMAX][VMAX];
bool up[NMAX];
int v[NMAX];
VI lines[NMAX];
int z[NMAX];

int color[NMAX];
bool u[NMAX];

bool ans;

vector< VI > trees;

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

bool crossDuga(VI &a, VI &b) {
    if (a.size() + b.size() < 4) return false;
    if (a[0] == b[0] || a[0] == b[1] || a[1] == b[0] || a[1] == b[1]) return false;
    bool f = (b[0] < a[0] && a[0] < b[1]);
    bool c = (b[0] < a[1] && a[1] < b[1]);
    return f ^ c;
}

VI edge(int a, int b) {
    VI x;
    x.pb(a); x.pb(b);
    return x;
}

void go(int v, VI &a) {
    if (u[v]) return ;
    u[v] = true;
    forv(i, vtree[v]) a.pb(vtree[v][i]);
    forn(i, k) if (g[v][i] != -1) go(i, a);
}

VI norm(VI a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    return a;
}

bool crossTree(VI &a, VI & b) {
    forv(i, a) forv(j, b) if (crossDuga(edge(a[i], a[(i + 1) % a.size()]), edge(b[j], b[(j + 1) % b.size()]))) 
        return true;
    return false;
}

bool go(int v, int c) {
    if (color[v] == -1) color[v] = c; else {
        return color[v] == c;
    }
    bool res = true;
    forv(i, trees) if (df[v][i]) res &= go(i, 1 - c);
    return res;
}

bool check() {
    forv(i, trees) {
        forn(j, i) {
            bool cbool = false;
            if (crossTree(trees[i], trees[j])) cbool = true;
            df[j][i] = df[i][j] = cbool;
        }
    }
    memset(color, 255, sizeof color);
    bool res = true;
    forv(i, trees) if (color[i] == -1) res &= go(i, 0);
    return res;
}

bool solveMask(int msk) {
    trees.clear();
    trees.reserve(k);
    int z = msk;
    bool ok = true;
    forn(i, k) {
        if (ens[i].size() == 0) continue;
        int x = z % 3;
        if (x == 0) {
            vtree[i] = ens[i];
        } else trees.pb(ens[i]);
        if (x == 1) {
            vtree[i].clear();
            if (ens[i].size() == 2) {
                vtree[i].pb(ens[i][0]);
            } else ok = false;
        }
        if (x == 2) {
            vtree[i].clear();
            if (ens[i].size() == 2) {
                vtree[i].pb(ens[i][1]);
            } else ok = false;
        }
        if (!ok) break;
        z /= 3;
    }
    if (!ok) return false;
    memset(u, 0, sizeof u);
    forn(i, k) if (!u[i]) {
        VI ctree;
        go(i, ctree);
        trees.pb(norm(ctree));
    }
    if (check()) {
        ans = true;
        return true;
    }
    return false;
}

void solve() {
    VI kn(k, 0);
    ens.clear();
    kCircle = 0;
    ens.resize(k);
    memset(g, 255, sizeof g);
    forn(i, n) {
        int t;
        scanf("%d", &t);
        assert(2 <= t && t <= k);
        VI x(t), y;
        forn(j, t) scanf("%d", &x[j]);
        forn(j, t) assert(0 <= x[j] && x[j] < k);
        lines[i] = x;
            y = x; sort(all(y)); y.erase(unique(all(y)), y.end()); assert(x == y);
        if (x[0] != 0) {
            forn(u, t) ++kn[x[u]];
            forn(u, t) --x[u];
            forn(u, t) forn(v, t) g[x[u]][x[v]] = g[x[v]][x[u]] = i;
        } else {
            ++kCircle;
            forn(u, t) ens[x[u]].pb(i);
        }
    }
    kp = n - kCircle;
    --k;
    ens.erase(ens.begin(), ens.begin() + 1);
    forn(i, k) {
        assert(ens[i].size() <= 2);
        sort(all(ens[i]));
    }
    forn(i, k) {
        assert(kn[i] <= 1);
    }
    ans = false;
    int r = (int)(pow(3.0, k) + .5);
    vtree.resize(k);
    cerr << r;
    forn(msk, r) {
        if (msk % 10000 == 0) cerr << msk << endl;
        if (solveMask(msk)) return ;
    }
}

void readdata() {
    string X;
    getline(cin, X);
    sscanf(X.c_str(), "%d", &k);
    assert(1 <= k && k <= 13);
    getline(cin, X);
    sscanf(X.c_str(), "%d", &n);
    assert(1 <= n && n <= 3 * k);
}

int main() {
        freopen(IN_FILE, "rt", stdin);
        freopen(OUT_FILE, "wt", stdout);
        readdata();
        solve();
        outdata();
        return 0;
}

